Completed
Pull Request — master (#747)
by Steve
19:06
created
includes/class-gvlogic-shortcode.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -225,7 +225,7 @@
 block discarded – undo
225 225
 	 * Does the if and the comparison match?
226 226
 	 * @uses GVCommon::matches_operation
227 227
 	 *
228
-	 * @return boolean True: yep; false: nope
228
+	 * @return boolean|null True: yep; false: nope
229 229
 	 */
230 230
 	function set_is_match() {
231 231
 		$this->is_match = GVCommon::matches_operation( $this->if, $this->comparison, $this->operation );
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	 */
86 86
 	public static function get_instance() {
87 87
 
88
-		if( empty( self::$instance ) ) {
88
+		if ( empty( self::$instance ) ) {
89 89
 			self::$instance = new self;
90 90
 		}
91 91
 
@@ -118,9 +118,9 @@  discard block
 block discarded – undo
118 118
 
119 119
 		$operators = array_merge( self::$SUPPORTED_ARRAY_OPERATORS, self::$SUPPORTED_NUMERIC_OPERATORS, self::$SUPPORTED_SCALAR_OPERATORS, self::$SUPPORTED_CUSTOM_OPERATORS );
120 120
 
121
-		if( $with_values ) {
121
+		if ( $with_values ) {
122 122
 			$operators_with_values = array();
123
-			foreach( $operators as $key ) {
123
+			foreach ( $operators as $key ) {
124 124
 				$operators_with_values[ $key ] = '';
125 125
 			}
126 126
 			return $operators_with_values;
@@ -137,14 +137,14 @@  discard block
 block discarded – undo
137 137
 	 */
138 138
 	function set_operation( $operation = '' ) {
139 139
 
140
-		if( empty( $operation ) ) {
140
+		if ( empty( $operation ) ) {
141 141
 			return false;
142 142
 		}
143 143
 
144 144
 		$operators = $this->get_operators( false );
145 145
 
146
-		if( !in_array( $operation, $operators ) ) {
147
-			do_action( 'gravityview_log_debug', __METHOD__ .' Attempted to add invalid operation type.', $operation );
146
+		if ( ! in_array( $operation, $operators ) ) {
147
+			do_action( 'gravityview_log_debug', __METHOD__ . ' Attempted to add invalid operation type.', $operation );
148 148
 			return false;
149 149
 		}
150 150
 
@@ -164,11 +164,11 @@  discard block
 block discarded – undo
164 164
 	 */
165 165
 	private function setup_operation_and_comparison() {
166 166
 
167
-		foreach( $this->atts as $key => $value ) {
167
+		foreach ( $this->atts as $key => $value ) {
168 168
 
169 169
 			$valid = $this->set_operation( $key );
170 170
 
171
-			if( $valid ) {
171
+			if ( $valid ) {
172 172
 				$this->comparison = $value;
173 173
 				return true;
174 174
 			}
@@ -191,8 +191,8 @@  discard block
 block discarded – undo
191 191
 			return null;
192 192
 		}
193 193
 
194
-		if( empty( $atts ) ) {
195
-			do_action( 'gravityview_log_error', __METHOD__.' $atts are empty.', $atts );
194
+		if ( empty( $atts ) ) {
195
+			do_action( 'gravityview_log_error', __METHOD__ . ' $atts are empty.', $atts );
196 196
 			return null;
197 197
 		}
198 198
 
@@ -203,16 +203,16 @@  discard block
 block discarded – undo
203 203
 		$this->parse_atts();
204 204
 
205 205
 		// We need an "if"
206
-		if( false === $this->if ) {
207
-			do_action( 'gravityview_log_error', __METHOD__.' $atts->if is empty.', $this->passed_atts );
206
+		if ( false === $this->if ) {
207
+			do_action( 'gravityview_log_error', __METHOD__ . ' $atts->if is empty.', $this->passed_atts );
208 208
 			return null;
209 209
 		}
210 210
 
211 211
 		$setup = $this->setup_operation_and_comparison();
212 212
 
213 213
 		// We need an operation and comparison value
214
-		if( ! $setup ) {
215
-			do_action( 'gravityview_log_error', __METHOD__.' No valid operators were passed.', $this->atts );
214
+		if ( ! $setup ) {
215
+			do_action( 'gravityview_log_error', __METHOD__ . ' No valid operators were passed.', $this->atts );
216 216
 			return null;
217 217
 		}
218 218
 
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 	 */
246 246
 	private function get_output() {
247 247
 
248
-		if( $this->is_match ) {
248
+		if ( $this->is_match ) {
249 249
 			$output = $this->content;
250 250
 		} else {
251 251
 			$output = $this->else_content;
@@ -259,9 +259,9 @@  discard block
 block discarded – undo
259 259
 		 * @param string $output HTML/text output
260 260
 		 * @param GVLogic_Shortcode $this This class
261 261
 		 */
262
-		$output = apply_filters('gravityview/gvlogic/output', $output, $this );
262
+		$output = apply_filters( 'gravityview/gvlogic/output', $output, $this );
263 263
 
264
-		do_action( 'gravityview_log_debug', __METHOD__ .' Output: ', $output );
264
+		do_action( 'gravityview_log_debug', __METHOD__ . ' Output: ', $output );
265 265
 
266 266
 		return $output;
267 267
 	}
@@ -277,11 +277,11 @@  discard block
 block discarded – undo
277 277
 
278 278
 		$content = explode( '[else]', $this->passed_content );
279 279
 
280
-		$this->content = $content[0];
280
+		$this->content = $content[ 0 ];
281 281
 
282
-		$else_attr = isset( $this->atts['else'] ) ? $this->atts['else'] : NULL;
282
+		$else_attr = isset( $this->atts[ 'else' ] ) ? $this->atts[ 'else' ] : NULL;
283 283
 
284
-		$this->else_content = isset( $content[1] ) ? $content[1] : $else_attr;
284
+		$this->else_content = isset( $content[ 1 ] ) ? $content[ 1 ] : $else_attr;
285 285
 	}
286 286
 
287 287
 	/**
@@ -304,10 +304,10 @@  discard block
 block discarded – undo
304 304
 		$this->atts = function_exists( 'array_intersect_key' ) ? array_intersect_key( $this->passed_atts, $this->atts ) : $this->atts;
305 305
 
306 306
 		// Strip whitespace if it's not default false
307
-		$this->if = is_string( $this->atts['if'] ) ? trim( $this->atts['if'] ) : false;
307
+		$this->if = is_string( $this->atts[ 'if' ] ) ? trim( $this->atts[ 'if' ] ) : false;
308 308
 
309 309
 		// Make sure the "if" isn't processed in self::setup_operation_and_comparison()
310
-		unset( $this->atts['if'] );
310
+		unset( $this->atts[ 'if' ] );
311 311
 	}
312 312
 }
313 313
 
Please login to merge, or discard this patch.
includes/class-oembed.php 2 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -211,6 +211,7 @@
 block discarded – undo
211 211
 	 * @var $view_id
212 212
 	 *
213 213
 	 * @see render_handler
214
+	 * @param string $url
214 215
 	 */
215 216
 	private function set_vars( $matches, $attr, $url, $rawattr ) {
216 217
 
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 */
43 43
 	static function getInstance() {
44 44
 
45
-		if( empty( self::$instance ) ) {
45
+		if ( empty( self::$instance ) ) {
46 46
 			self::$instance = new self;
47 47
 
48 48
 			self::$instance->initialize();
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 		// Catch either
95 95
 		$match_regex = "(?:{$using_permalinks}|{$not_using_permalinks})";
96 96
 
97
-		return '#'.$match_regex.'#i';
97
+		return '#' . $match_regex . '#i';
98 98
 	}
99 99
 
100 100
 	/**
@@ -113,18 +113,18 @@  discard block
 block discarded – undo
113 113
 
114 114
 		$post_id = url_to_postid( $url );
115 115
 
116
-		if( empty( $post_id ) ) {
116
+		if ( empty( $post_id ) ) {
117 117
 
118 118
 			$args = array(
119 119
 				'post_status' => 'publish',
120 120
 				'name' => $slug,
121
-				'post_type' => array('any', 'gravityview'),
121
+				'post_type' => array( 'any', 'gravityview' ),
122 122
 			);
123 123
 
124 124
 			$posts = get_posts( $args );
125 125
 
126
-			if( !empty( $posts ) ) {
127
-				$post_id = $posts[0]->ID;
126
+			if ( ! empty( $posts ) ) {
127
+				$post_id = $posts[ 0 ]->ID;
128 128
 			}
129 129
 		}
130 130
 
@@ -157,17 +157,17 @@  discard block
 block discarded – undo
157 157
 	public function render_handler( $matches, $attr, $url, $rawattr ) {
158 158
 
159 159
 		// If not using permalinks, re-assign values for matching groups
160
-		if( !empty( $matches['entry_slug2'] ) ) {
161
-			$matches['is_cpt'] = $matches['is_cpt2'];
162
-			$matches['slug'] = $matches['slug2'];
163
-			$matches['entry_slug'] = $matches['entry_slug2'];
164
-			unset( $matches['is_cpt2'], $matches['slug2'], $matches['entry_slug2'] );
160
+		if ( ! empty( $matches[ 'entry_slug2' ] ) ) {
161
+			$matches[ 'is_cpt' ] = $matches[ 'is_cpt2' ];
162
+			$matches[ 'slug' ] = $matches[ 'slug2' ];
163
+			$matches[ 'entry_slug' ] = $matches[ 'entry_slug2' ];
164
+			unset( $matches[ 'is_cpt2' ], $matches[ 'slug2' ], $matches[ 'entry_slug2' ] );
165 165
 		}
166 166
 
167 167
 		// No Entry was found
168
-		if( empty( $matches['entry_slug'] ) ) {
168
+		if ( empty( $matches[ 'entry_slug' ] ) ) {
169 169
 
170
-			do_action('gravityview_log_error', 'GravityView_oEmbed[render_handler] $entry_slug not parsed by regex.', $matches );
170
+			do_action( 'gravityview_log_error', 'GravityView_oEmbed[render_handler] $entry_slug not parsed by regex.', $matches );
171 171
 
172 172
 			return '';
173 173
 		}
@@ -177,11 +177,11 @@  discard block
 block discarded – undo
177 177
 		// Setup the data used
178 178
 		$this->set_vars( $matches, $attr, $url, $rawattr );
179 179
 
180
-		if( is_admin() && !$this->is_full_oembed_preview ) {
180
+		if ( is_admin() && ! $this->is_full_oembed_preview ) {
181 181
 			$return = $this->render_admin( $matches, $attr, $url, $rawattr );
182 182
 		} else {
183 183
 
184
-			if( $this->is_full_oembed_preview ) {
184
+			if ( $this->is_full_oembed_preview ) {
185 185
 				$return .= $this->generate_preview_notice();
186 186
 			}
187 187
 
@@ -200,8 +200,8 @@  discard block
 block discarded – undo
200 200
 	private function generate_preview_notice() {
201 201
 		$floaty = GravityView_Admin::get_floaty();
202 202
 		$title = esc_html__( 'This will look better when it is embedded.', 'gravityview' );
203
-		$message = esc_html__('Styles don\'t get loaded when being previewed, so the content below will look strange. Don\'t be concerned!', 'gravityview');
204
-		return '<div class="updated notice">'. $floaty. '<h3>'.$title.'</h3><p>'.$message.'</p><br style="clear:both;" /></div>';
203
+		$message = esc_html__( 'Styles don\'t get loaded when being previewed, so the content below will look strange. Don\'t be concerned!', 'gravityview' );
204
+		return '<div class="updated notice">' . $floaty . '<h3>' . $title . '</h3><p>' . $message . '</p><br style="clear:both;" /></div>';
205 205
 	}
206 206
 
207 207
 	/**
@@ -214,14 +214,14 @@  discard block
 block discarded – undo
214 214
 	 */
215 215
 	private function set_vars( $matches, $attr, $url, $rawattr ) {
216 216
 
217
-		$this->entry_id = $matches['entry_slug'];
217
+		$this->entry_id = $matches[ 'entry_slug' ];
218 218
 
219
-		$post_id = $this->get_postid_from_url_and_slug( $url, $matches['slug'] );
219
+		$post_id = $this->get_postid_from_url_and_slug( $url, $matches[ 'slug' ] );
220 220
 
221 221
 		// The URL didn't have the View Custom Post Type structure.
222
-		if( empty( $matches['is_cpt'] ) || $matches['is_cpt'] !== 'gravityview' ) {
222
+		if ( empty( $matches[ 'is_cpt' ] ) || $matches[ 'is_cpt' ] !== 'gravityview' ) {
223 223
 
224
-			do_action('gravityview_log_debug', 'GravityView_oEmbed[render_handler] Embedding an entry inside a post or page', $matches );
224
+			do_action( 'gravityview_log_debug', 'GravityView_oEmbed[render_handler] Embedding an entry inside a post or page', $matches );
225 225
 
226 226
 			$this->view_id = GravityView_View_Data::getInstance()->maybe_get_view_id( $post_id );
227 227
 
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 		}
233 233
 
234 234
 		// The inline content has $_POST['type'] set to "embed", while the "Add Media" modal doesn't set that.
235
-		$this->is_full_oembed_preview = ( isset( $_POST['action'] ) && $_POST['action'] === 'parse-embed' && !isset( $_POST['type'] ) );
235
+		$this->is_full_oembed_preview = ( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] === 'parse-embed' && ! isset( $_POST[ 'type' ] ) );
236 236
 	}
237 237
 
238 238
 	/**
@@ -250,15 +250,15 @@  discard block
 block discarded – undo
250 250
 		// Floaty the astronaut
251 251
 		$image = GravityView_Admin::get_floaty();
252 252
 
253
-		$embed_heading = sprintf( esc_html__('Embed Entry %d', 'gravityview'), $this->entry_id );
253
+		$embed_heading = sprintf( esc_html__( 'Embed Entry %d', 'gravityview' ), $this->entry_id );
254 254
 
255
-		$embed_text = sprintf( esc_html__('This entry will be displayed as it is configured in View %d', 'gravityview'), $this->view_id );
255
+		$embed_text = sprintf( esc_html__( 'This entry will be displayed as it is configured in View %d', 'gravityview' ), $this->view_id );
256 256
 
257 257
 		return '
258 258
 		<div class="loading-placeholder" style="background-color:#e6f0f5;">
259
-			<h3 style="margin:0; padding:0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">'.$image.$embed_heading.'</h3>
259
+			<h3 style="margin:0; padding:0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">'.$image . $embed_heading . '</h3>
260 260
 			<p style="margin:0; padding:0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">
261
-				'.$embed_text.'
261
+				'.$embed_text . '
262 262
 			</p>
263 263
 			<br style="clear: both;">
264 264
 		</div>';
@@ -313,14 +313,14 @@  discard block
 block discarded – undo
313 313
 	private function render_frontend( $matches, $attr, $url, $rawattr ) {
314 314
 
315 315
 		// If it's already been parsed, don't re-output it.
316
-		if( !empty( $this->output[ $this->entry_id ] ) ) {
316
+		if ( ! empty( $this->output[ $this->entry_id ] ) ) {
317 317
 			return $this->output[ $this->entry_id ];
318 318
 		}
319 319
 
320 320
 		$entry_output = $this->generate_entry_output();
321 321
 
322 322
 		// Wrap a container div around the output to allow for custom styling
323
-		$output = sprintf('<div class="gravityview-oembed gravityview-oembed-entry gravityview-oembed-entry-'.$this->entry_id.'">%s</div>', $entry_output );
323
+		$output = sprintf( '<div class="gravityview-oembed gravityview-oembed-entry gravityview-oembed-entry-' . $this->entry_id . '">%s</div>', $entry_output );
324 324
 
325 325
 		/**
326 326
 		 * @filter `gravityview/oembed/entry` Filter the output of the oEmbed entry embed
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 		 *  @var string $url The original URL that was matched by the regex. \n
334 334
 		 *  @var array $rawattr The original unmodified attributes.
335 335
 		 */
336
-		$output = apply_filters('gravityview/oembed/entry', $output, $this, compact( $entry_output, $matches, $attr, $url, $rawattr ) );
336
+		$output = apply_filters( 'gravityview/oembed/entry', $output, $this, compact( $entry_output, $matches, $attr, $url, $rawattr ) );
337 337
 
338 338
 		unset( $entry_output );
339 339
 
Please login to merge, or discard this patch.
includes/extensions/delete-entry/class-delete-entry.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -170,7 +170,6 @@
 block discarded – undo
170 170
 	 *
171 171
 	 * @since 1.5.1
172 172
 	 * @param  array 	   $visibility_caps        Array of capabilities to display in field dropdown.
173
-	 * @param  string      $field_type  Type of field options to render (`field` or `widget`)
174 173
 	 * @param  string      $template_id Table slug
175 174
 	 * @param  float       $field_id    GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by`
176 175
 	 * @param  string      $context     What context are we in? Example: `single` or `directory`
Please login to merge, or discard this patch.
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 
229 229
 		self::getInstance()->set_entry( $entry );
230 230
 
231
-        $base = GravityView_API::directory_link( $post_id, true );
231
+		$base = GravityView_API::directory_link( $post_id, true );
232 232
 
233 233
 		if( empty( $base ) ) {
234 234
 			do_action( 'gravityview_log_error', __METHOD__ . ' - Post ID does not exist: '.$post_id );
@@ -238,13 +238,13 @@  discard block
 block discarded – undo
238 238
 		// Use the slug instead of the ID for consistent security
239 239
 		$entry_slug = GravityView_API::get_entry_slug( $entry['id'], $entry );
240 240
 
241
-        $view_id = empty( $view_id ) ? gravityview_get_view_id() : $view_id;
241
+		$view_id = empty( $view_id ) ? gravityview_get_view_id() : $view_id;
242 242
 
243 243
 		$actionurl = add_query_arg( array(
244 244
 			'action'	=> 'delete',
245 245
 			'entry_id'		=> $entry_slug,
246 246
 			'gvid' => $view_id,
247
-            'view_id' => $view_id,
247
+			'view_id' => $view_id,
248 248
 		), $base );
249 249
 
250 250
 		$url = wp_nonce_url( $actionurl, 'delete_'.$entry_slug, 'delete' );
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
 				 * @action `gravityview/delete-entry/deleted` Triggered when an entry is deleted
416 416
 				 * @since 1.16.4
417 417
 				 * @param  int $entry_id ID of the Gravity Forms entry
418
-				*/
418
+				 */
419 419
 				do_action( 'gravityview/delete-entry/deleted', $entry_id );
420 420
 			}
421 421
 
Please login to merge, or discard this patch.
Spacing   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -42,12 +42,12 @@  discard block
 block discarded – undo
42 42
 
43 43
 		add_action( 'wp', array( $this, 'process_delete' ), 10000 );
44 44
 
45
-		add_filter( 'gravityview_entry_default_fields', array( $this, 'add_default_field'), 10, 3 );
45
+		add_filter( 'gravityview_entry_default_fields', array( $this, 'add_default_field' ), 10, 3 );
46 46
 
47 47
 		add_action( 'gravityview_before', array( $this, 'display_message' ) );
48 48
 
49 49
 		// For the Delete Entry Link, you don't want visible to all users.
50
-		add_filter( 'gravityview_field_visibility_caps', array( $this, 'modify_visibility_caps'), 10, 5 );
50
+		add_filter( 'gravityview_field_visibility_caps', array( $this, 'modify_visibility_caps' ), 10, 5 );
51 51
 
52 52
 		// Modify the field options based on the name of the field type
53 53
 		add_filter( 'gravityview_template_delete_link_options', array( $this, 'delete_link_field_options' ), 10, 5 );
@@ -55,10 +55,10 @@  discard block
 block discarded – undo
55 55
 		// add template path to check for field
56 56
 		add_filter( 'gravityview_template_paths', array( $this, 'add_template_path' ) );
57 57
 
58
-		add_action( 'gravityview/edit-entry/publishing-action/after', array( $this, 'add_delete_button'), 10, 3 );
58
+		add_action( 'gravityview/edit-entry/publishing-action/after', array( $this, 'add_delete_button' ), 10, 3 );
59 59
 
60
-		add_action ( 'gravityview/delete-entry/deleted', array( $this, 'process_connected_posts' ), 10, 2 );
61
-		add_action ( 'gravityview/delete-entry/trashed', array( $this, 'process_connected_posts' ), 10, 2 );
60
+		add_action( 'gravityview/delete-entry/deleted', array( $this, 'process_connected_posts' ), 10, 2 );
61
+		add_action( 'gravityview/delete-entry/trashed', array( $this, 'process_connected_posts' ), 10, 2 );
62 62
 	}
63 63
 
64 64
 	/**
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 */
70 70
 	static function getInstance() {
71 71
 
72
-		if( empty( self::$instance ) ) {
72
+		if ( empty( self::$instance ) ) {
73 73
 			self::$instance = new self;
74 74
 		}
75 75
 
@@ -105,20 +105,20 @@  discard block
 block discarded – undo
105 105
 	function delete_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
106 106
 
107 107
 		// Always a link, never a filter
108
-		unset( $field_options['show_as_link'], $field_options['search_filter'] );
108
+		unset( $field_options[ 'show_as_link' ], $field_options[ 'search_filter' ] );
109 109
 
110 110
 		// Delete Entry link should only appear to visitors capable of editing entries
111
-		unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] );
111
+		unset( $field_options[ 'only_loggedin' ], $field_options[ 'only_loggedin_cap' ] );
112 112
 
113
-		$add_option['delete_link'] = array(
113
+		$add_option[ 'delete_link' ] = array(
114 114
 			'type' => 'text',
115 115
 			'label' => __( 'Delete Link Text', 'gravityview' ),
116 116
 			'desc' => NULL,
117
-			'value' => __('Delete Entry', 'gravityview'),
117
+			'value' => __( 'Delete Entry', 'gravityview' ),
118 118
 			'merge_tags' => true,
119 119
 		);
120 120
 
121
-		$field_options['allow_edit_cap'] = array(
121
+		$field_options[ 'allow_edit_cap' ] = array(
122 122
 			'type' => 'select',
123 123
 			'label' => __( 'Allow the following users to delete the entry:', 'gravityview' ),
124 124
 			'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ),
@@ -142,10 +142,10 @@  discard block
 block discarded – undo
142 142
 	 */
143 143
 	function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) {
144 144
 
145
-		$entry_default_fields['delete_link'] = array(
146
-			'label' => __('Delete Entry', 'gravityview'),
145
+		$entry_default_fields[ 'delete_link' ] = array(
146
+			'label' => __( 'Delete Entry', 'gravityview' ),
147 147
 			'type' => 'delete_link',
148
-			'desc'	=> __('A link to delete the entry. Respects the Delete Entry permissions.', 'gravityview'),
148
+			'desc'	=> __( 'A link to delete the entry. Respects the Delete Entry permissions.', 'gravityview' ),
149 149
 		);
150 150
 
151 151
 		return $entry_default_fields;
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 	 */
159 159
 	function add_available_field( $available_fields = array() ) {
160 160
 
161
-		$available_fields['delete_link'] = array(
161
+		$available_fields[ 'delete_link' ] = array(
162 162
 			'label_text' => __( 'Delete Entry', 'gravityview' ),
163 163
 			'field_id' => 'delete_link',
164 164
 			'label_type' => 'field',
@@ -186,12 +186,12 @@  discard block
 block discarded – undo
186 186
 		$caps = $visibility_caps;
187 187
 
188 188
 		// If we're configuring fields in the edit context, we want a limited selection
189
-		if( $field_id === 'delete_link' ) {
189
+		if ( $field_id === 'delete_link' ) {
190 190
 
191 191
 			// Remove other built-in caps.
192
-			unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] );
192
+			unset( $caps[ 'publish_posts' ], $caps[ 'gravityforms_view_entries' ], $caps[ 'delete_others_posts' ] );
193 193
 
194
-			$caps['read'] = _x('Entry Creator', 'User capability', 'gravityview');
194
+			$caps[ 'read' ] = _x( 'Entry Creator', 'User capability', 'gravityview' );
195 195
 		}
196 196
 
197 197
 		return $caps;
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 	 * @param [type] $entry [description]
205 205
 	 */
206 206
 	function set_entry( $entry = null ) {
207
-		$this->entry = empty( $entry ) ? GravityView_View::getInstance()->entries[0] : $entry;
207
+		$this->entry = empty( $entry ) ? GravityView_View::getInstance()->entries[ 0 ] : $entry;
208 208
 	}
209 209
 
210 210
 	/**
@@ -234,13 +234,13 @@  discard block
 block discarded – undo
234 234
 
235 235
         $base = GravityView_API::directory_link( $post_id, true );
236 236
 
237
-		if( empty( $base ) ) {
238
-			do_action( 'gravityview_log_error', __METHOD__ . ' - Post ID does not exist: '.$post_id );
237
+		if ( empty( $base ) ) {
238
+			do_action( 'gravityview_log_error', __METHOD__ . ' - Post ID does not exist: ' . $post_id );
239 239
 			return NULL;
240 240
 		}
241 241
 
242 242
 		// Use the slug instead of the ID for consistent security
243
-		$entry_slug = GravityView_API::get_entry_slug( $entry['id'], $entry );
243
+		$entry_slug = GravityView_API::get_entry_slug( $entry[ 'id' ], $entry );
244 244
 
245 245
         $view_id = empty( $view_id ) ? gravityview_get_view_id() : $view_id;
246 246
 
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
             'view_id' => $view_id,
252 252
 		), $base );
253 253
 
254
-		$url = wp_nonce_url( $actionurl, 'delete_'.$entry_slug, 'delete' );
254
+		$url = wp_nonce_url( $actionurl, 'delete_' . $entry_slug, 'delete' );
255 255
 
256 256
 		return $url;
257 257
 	}
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 	function add_delete_button( $form = array(), $entry = array(), $view_id = NULL ) {
269 269
 
270 270
 		// Only show the link to those who are allowed to see it.
271
-		if( !self::check_user_cap_delete_entry( $entry ) ) {
271
+		if ( ! self::check_user_cap_delete_entry( $entry ) ) {
272 272
 			return;
273 273
 		}
274 274
 
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 		$show_delete_button = apply_filters( 'gravityview/delete-entry/show-delete-button', true );
280 280
 
281 281
 		// If the button is hidden by the filter, don't show.
282
-		if( !$show_delete_button ) {
282
+		if ( ! $show_delete_button ) {
283 283
 			return;
284 284
 		}
285 285
 
@@ -309,27 +309,27 @@  discard block
 block discarded – undo
309 309
 	function process_delete() {
310 310
 
311 311
 		// If the form is submitted
312
-		if( isset( $_GET['action'] ) && 'delete' === $_GET['action'] && isset( $_GET['entry_id'] ) ) {
312
+		if ( isset( $_GET[ 'action' ] ) && 'delete' === $_GET[ 'action' ] && isset( $_GET[ 'entry_id' ] ) ) {
313 313
 
314 314
 			// Make sure it's a GravityView request
315
-			$valid_nonce_key = wp_verify_nonce( $_GET['delete'], self::get_nonce_key( $_GET['entry_id'] ) );
315
+			$valid_nonce_key = wp_verify_nonce( $_GET[ 'delete' ], self::get_nonce_key( $_GET[ 'entry_id' ] ) );
316 316
 
317
-			if( ! $valid_nonce_key ) {
318
-				do_action('gravityview_log_debug', __METHOD__ . ' Delete entry not processed: nonce validation failed.' );
317
+			if ( ! $valid_nonce_key ) {
318
+				do_action( 'gravityview_log_debug', __METHOD__ . ' Delete entry not processed: nonce validation failed.' );
319 319
 				return;
320 320
 			}
321 321
 
322 322
 			// Get the entry slug
323
-			$entry_slug = esc_attr( $_GET['entry_id'] );
323
+			$entry_slug = esc_attr( $_GET[ 'entry_id' ] );
324 324
 
325 325
 			// See if there's an entry there
326 326
 			$entry = gravityview_get_entry( $entry_slug );
327 327
 
328
-			if( $entry ) {
328
+			if ( $entry ) {
329 329
 
330 330
 				$has_permission = $this->user_can_delete_entry( $entry );
331 331
 
332
-				if( is_wp_error( $has_permission ) ) {
332
+				if ( is_wp_error( $has_permission ) ) {
333 333
 
334 334
 					$messages = array(
335 335
 						'message' => urlencode( $has_permission->get_error_message() ),
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 					// Delete the entry
342 342
 					$delete_response = $this->delete_or_trash_entry( $entry );
343 343
 
344
-					if( is_wp_error( $delete_response ) ) {
344
+					if ( is_wp_error( $delete_response ) ) {
345 345
 
346 346
 						$messages = array(
347 347
 							'message' => urlencode( $delete_response->get_error_message() ),
@@ -360,10 +360,10 @@  discard block
 block discarded – undo
360 360
 
361 361
 			} else {
362 362
 
363
-				do_action('gravityview_log_debug', __METHOD__ . ' Delete entry failed: there was no entry with the entry slug '. $entry_slug );
363
+				do_action( 'gravityview_log_debug', __METHOD__ . ' Delete entry failed: there was no entry with the entry slug ' . $entry_slug );
364 364
 
365 365
 				$messages = array(
366
-					'message' => urlencode( __('The entry does not exist.', 'gravityview') ),
366
+					'message' => urlencode( __( 'The entry does not exist.', 'gravityview' ) ),
367 367
 					'status' => 'error',
368 368
 				);
369 369
 			}
@@ -403,18 +403,18 @@  discard block
 block discarded – undo
403 403
 	 */
404 404
 	private function delete_or_trash_entry( $entry ) {
405 405
 
406
-		$entry_id = $entry['id'];
406
+		$entry_id = $entry[ 'id' ];
407 407
 		
408 408
 		$mode = $this->get_delete_mode();
409 409
 
410
-		if( 'delete' === $mode ) {
410
+		if ( 'delete' === $mode ) {
411 411
 
412 412
 			do_action( 'gravityview_log_debug', __METHOD__ . ' Starting delete entry: ', $entry_id );
413 413
 
414 414
 			// Delete the entry
415 415
 			$delete_response = GFAPI::delete_entry( $entry_id );
416 416
 
417
-			if( ! is_wp_error( $delete_response ) ) {
417
+			if ( ! is_wp_error( $delete_response ) ) {
418 418
 				$delete_response = 'deleted';
419 419
 
420 420
 				/**
@@ -435,8 +435,8 @@  discard block
 block discarded – undo
435 435
 			$trashed = GFAPI::update_entry_property( $entry_id, 'status', 'trash' );
436 436
 			new GravityView_Cache;
437 437
 
438
-			if( ! $trashed ) {
439
-				$delete_response = new WP_Error( 'trash_entry_failed', __('Moving the entry to the trash failed.', 'gravityview' ) );
438
+			if ( ! $trashed ) {
439
+				$delete_response = new WP_Error( 'trash_entry_failed', __( 'Moving the entry to the trash failed.', 'gravityview' ) );
440 440
 			} else {
441 441
 
442 442
 				/**
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 	public function process_connected_posts( $entry_id = 0, $entry = array() ) {
468 468
 
469 469
 		// The entry had no connected post
470
-		if( empty( $entry['post_id'] ) ) {
470
+		if ( empty( $entry[ 'post_id' ] ) ) {
471 471
 			return;
472 472
 		}
473 473
 
@@ -478,22 +478,22 @@  discard block
 block discarded – undo
478 478
 		 */
479 479
 		$delete_post = apply_filters( 'gravityview/delete-entry/delete-connected-post', true );
480 480
 		
481
-		if( false === $delete_post ) {
481
+		if ( false === $delete_post ) {
482 482
 			return;
483 483
 		}
484 484
 
485 485
 		$action = current_action();
486 486
 
487
-		if( 'gravityview/delete-entry/deleted' === $action ) {
488
-			$result = wp_delete_post( $entry['post_id'], true );
487
+		if ( 'gravityview/delete-entry/deleted' === $action ) {
488
+			$result = wp_delete_post( $entry[ 'post_id' ], true );
489 489
 		} else {
490
-			$result = wp_trash_post( $entry['post_id'] );
490
+			$result = wp_trash_post( $entry[ 'post_id' ] );
491 491
 		}
492 492
 
493
-		if( false === $result ) {
494
-			do_action( 'gravityview_log_error', __METHOD__ . ' (called by '.$action.'): Error processing the Post connected to the entry.', $entry );
493
+		if ( false === $result ) {
494
+			do_action( 'gravityview_log_error', __METHOD__ . ' (called by ' . $action . '): Error processing the Post connected to the entry.', $entry );
495 495
 		} else {
496
-			do_action( 'gravityview_log_debug', __METHOD__ . ' (called by '.$action.'): Successfully processed Post connected to the entry.', $entry );
496
+			do_action( 'gravityview_log_debug', __METHOD__ . ' (called by ' . $action . '): Successfully processed Post connected to the entry.', $entry );
497 497
 		}
498 498
 	}
499 499
 
@@ -506,13 +506,13 @@  discard block
 block discarded – undo
506 506
 	public function verify_nonce() {
507 507
 
508 508
 		// No delete entry request was made
509
-		if( empty( $_GET['entry_id'] ) || empty( $_GET['delete'] ) ) {
509
+		if ( empty( $_GET[ 'entry_id' ] ) || empty( $_GET[ 'delete' ] ) ) {
510 510
 			return false;
511 511
 		}
512 512
 
513
-		$nonce_key = self::get_nonce_key( $_GET['entry_id'] );
513
+		$nonce_key = self::get_nonce_key( $_GET[ 'entry_id' ] );
514 514
 
515
-		$valid = wp_verify_nonce( $_GET['delete'], $nonce_key );
515
+		$valid = wp_verify_nonce( $_GET[ 'delete' ], $nonce_key );
516 516
 
517 517
 		/**
518 518
 		 * @filter `gravityview/delete-entry/verify_nonce` Override Delete Entry nonce validation. Return true to declare nonce valid.
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
 	 */
535 535
 	public static function get_confirm_dialog() {
536 536
 
537
-		$confirm = __('Are you sure you want to delete this entry? This cannot be undone.', 'gravityview');
537
+		$confirm = __( 'Are you sure you want to delete this entry? This cannot be undone.', 'gravityview' );
538 538
 
539 539
 		/**
540 540
 		 * @filter `gravityview/delete-entry/confirm-text` Modify the Delete Entry Javascript confirmation text
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
 		 */
543 543
 		$confirm = apply_filters( 'gravityview/delete-entry/confirm-text', $confirm );
544 544
 
545
-		return 'return window.confirm(\''. esc_js( $confirm ) .'\');';
545
+		return 'return window.confirm(\'' . esc_js( $confirm ) . '\');';
546 546
 	}
547 547
 
548 548
 	/**
@@ -560,16 +560,16 @@  discard block
 block discarded – undo
560 560
 
561 561
 		$error = NULL;
562 562
 
563
-		if( ! $this->verify_nonce() ) {
564
-			$error = __( 'The link to delete this entry is not valid; it may have expired.', 'gravityview');
563
+		if ( ! $this->verify_nonce() ) {
564
+			$error = __( 'The link to delete this entry is not valid; it may have expired.', 'gravityview' );
565 565
 		}
566 566
 
567
-		if( ! self::check_user_cap_delete_entry( $entry ) ) {
568
-			$error = __( 'You do not have permission to delete this entry.', 'gravityview');
567
+		if ( ! self::check_user_cap_delete_entry( $entry ) ) {
568
+			$error = __( 'You do not have permission to delete this entry.', 'gravityview' );
569 569
 		}
570 570
 
571
-		if( $entry['status'] === 'trash' ) {
572
-			if( 'trash' === $this->get_delete_mode() ) {
571
+		if ( $entry[ 'status' ] === 'trash' ) {
572
+			if ( 'trash' === $this->get_delete_mode() ) {
573 573
 				$error = __( 'The entry is already in the trash.', 'gravityview' );
574 574
 			} else {
575 575
 				$error = __( 'You cannot delete the entry; it is already in the trash.', 'gravityview' );
@@ -577,11 +577,11 @@  discard block
 block discarded – undo
577 577
 		}
578 578
 
579 579
 		// No errors; everything's fine here!
580
-		if( empty( $error ) ) {
580
+		if ( empty( $error ) ) {
581 581
 			return true;
582 582
 		}
583 583
 
584
-		do_action('gravityview_log_error', 'GravityView_Delete_Entry[user_can_delete_entry]' . $error );
584
+		do_action( 'gravityview_log_error', 'GravityView_Delete_Entry[user_can_delete_entry]' . $error );
585 585
 
586 586
 		return new WP_Error( 'gravityview-delete-entry-permissions', $error );
587 587
 	}
@@ -603,32 +603,32 @@  discard block
 block discarded – undo
603 603
 
604 604
 		$current_user = wp_get_current_user();
605 605
 
606
-		$entry_id = isset( $entry['id'] ) ? $entry['id'] : NULL;
606
+		$entry_id = isset( $entry[ 'id' ] ) ? $entry[ 'id' ] : NULL;
607 607
 
608 608
 		// Or if they can delete any entries (as defined in Gravity Forms), we're good.
609
-		if( GVCommon::has_cap( array( 'gravityforms_delete_entries', 'gravityview_delete_others_entries' ), $entry_id ) ) {
609
+		if ( GVCommon::has_cap( array( 'gravityforms_delete_entries', 'gravityview_delete_others_entries' ), $entry_id ) ) {
610 610
 
611
-			do_action('gravityview_log_debug', 'GravityView_Delete_Entry[check_user_cap_delete_entry] Current user has `gravityforms_delete_entries` or `gravityview_delete_others_entries` capability.' );
611
+			do_action( 'gravityview_log_debug', 'GravityView_Delete_Entry[check_user_cap_delete_entry] Current user has `gravityforms_delete_entries` or `gravityview_delete_others_entries` capability.' );
612 612
 
613 613
 			return true;
614 614
 		}
615 615
 
616 616
 
617 617
 		// If field options are passed, check if current user can view the link
618
-		if( !empty( $field ) ) {
618
+		if ( ! empty( $field ) ) {
619 619
 
620 620
 			// If capability is not defined, something is not right!
621
-			if( empty( $field['allow_edit_cap'] ) ) {
621
+			if ( empty( $field[ 'allow_edit_cap' ] ) ) {
622 622
 
623 623
 				do_action( 'gravityview_log_error', 'GravityView_Delete_Entry[check_user_cap_delete_entry] Cannot read delete entry field caps', $field );
624 624
 
625 625
 				return false;
626 626
 			}
627 627
 
628
-			if( GVCommon::has_cap( $field['allow_edit_cap'] ) ) {
628
+			if ( GVCommon::has_cap( $field[ 'allow_edit_cap' ] ) ) {
629 629
 
630 630
 				// Do not return true if cap is read, as we need to check if the current user created the entry
631
-				if( $field['allow_edit_cap'] !== 'read' ) {
631
+				if ( $field[ 'allow_edit_cap' ] !== 'read' ) {
632 632
 					return true;
633 633
 				}
634 634
 
@@ -641,9 +641,9 @@  discard block
 block discarded – undo
641 641
 
642 642
 		}
643 643
 
644
-		if( !isset( $entry['created_by'] ) ) {
644
+		if ( ! isset( $entry[ 'created_by' ] ) ) {
645 645
 
646
-			do_action('gravityview_log_error', 'GravityView_Delete_Entry[check_user_cap_delete_entry] Entry `created_by` doesn\'t exist.');
646
+			do_action( 'gravityview_log_error', 'GravityView_Delete_Entry[check_user_cap_delete_entry] Entry `created_by` doesn\'t exist.' );
647 647
 
648 648
 			return false;
649 649
 		}
@@ -651,24 +651,24 @@  discard block
 block discarded – undo
651 651
 		$view_id = empty( $view_id ) ? $gravityview_view->getViewId() : $view_id;
652 652
 
653 653
 		// Only checks user_delete view option if view is already set
654
-		if( $view_id ) {
654
+		if ( $view_id ) {
655 655
 
656 656
 			$current_view = gravityview_get_current_view_data( $view_id );
657 657
 
658
-			$user_delete = isset( $current_view['atts']['user_delete'] ) ? $current_view['atts']['user_delete'] : false;
658
+			$user_delete = isset( $current_view[ 'atts' ][ 'user_delete' ] ) ? $current_view[ 'atts' ][ 'user_delete' ] : false;
659 659
 
660
-			if( empty( $user_delete ) ) {
660
+			if ( empty( $user_delete ) ) {
661 661
 
662
-				do_action('gravityview_log_debug', 'GravityView_Delete_Entry[check_user_cap_delete_entry] User Delete is disabled. Returning false.' );
662
+				do_action( 'gravityview_log_debug', 'GravityView_Delete_Entry[check_user_cap_delete_entry] User Delete is disabled. Returning false.' );
663 663
 
664 664
 				return false;
665 665
 			}
666 666
 		}
667 667
 
668 668
 		// If the logged-in user is the same as the user who created the entry, we're good.
669
-		if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) {
669
+		if ( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry[ 'created_by' ] ) ) {
670 670
 
671
-			do_action('gravityview_log_debug', sprintf( 'GravityView_Delete_Entry[check_user_cap_delete_entry] User %s created the entry.', $current_user->ID ) );
671
+			do_action( 'gravityview_log_debug', sprintf( 'GravityView_Delete_Entry[check_user_cap_delete_entry] User %s created the entry.', $current_user->ID ) );
672 672
 
673 673
 			return true;
674 674
 		}
@@ -691,31 +691,31 @@  discard block
 block discarded – undo
691 691
 	 */
692 692
 	public function display_message( $current_view_id = 0 ) {
693 693
 
694
-		if( empty( $_GET['status'] ) || ! self::verify_nonce() ) {
694
+		if ( empty( $_GET[ 'status' ] ) || ! self::verify_nonce() ) {
695 695
 			return;
696 696
 		}
697 697
 
698 698
 		// Entry wasn't deleted from current View
699
-		if( intval( $_GET['gvid'] ) !== intval( $current_view_id ) ) {
699
+		if ( intval( $_GET[ 'gvid' ] ) !== intval( $current_view_id ) ) {
700 700
 			return;
701 701
 		}
702 702
 
703
-		$status = esc_attr( $_GET['status'] );
704
-		$message_from_url = rgget('message');
703
+		$status = esc_attr( $_GET[ 'status' ] );
704
+		$message_from_url = rgget( 'message' );
705 705
 		$message_from_url = urldecode( stripslashes_deep( $message_from_url ) );
706 706
 		$class = '';
707 707
 
708 708
 		switch ( $status ) {
709 709
 			case 'error':
710 710
 				$class = ' gv-error error';
711
-				$error_message = __('There was an error deleting the entry: %s', 'gravityview');
711
+				$error_message = __( 'There was an error deleting the entry: %s', 'gravityview' );
712 712
 				$message = sprintf( $error_message, $message_from_url );
713 713
 				break;
714 714
 			case 'trashed':
715
-				$message = __('The entry was successfully moved to the trash.', 'gravityview');
715
+				$message = __( 'The entry was successfully moved to the trash.', 'gravityview' );
716 716
 				break;
717 717
 			default:
718
-				$message = __('The entry was successfully deleted.', 'gravityview');
718
+				$message = __( 'The entry was successfully deleted.', 'gravityview' );
719 719
 				break;
720 720
 		}
721 721
 
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
 		$message = apply_filters( 'gravityview/delete-entry/message', esc_attr( $message ), $status, $message_from_url );
730 730
 
731 731
 		// DISPLAY ERROR/SUCCESS MESSAGE
732
-		echo '<div class="gv-notice' . esc_attr( $class ) .'">'. $message .'</div>';
732
+		echo '<div class="gv-notice' . esc_attr( $class ) . '">' . $message . '</div>';
733 733
 	}
734 734
 
735 735
 
Please login to merge, or discard this patch.
includes/extensions/edit-entry/class-edit-entry-admin.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -69,7 +69,6 @@
 block discarded – undo
69 69
      * Change wording for the Edit context to read Entry Creator
70 70
      *
71 71
      * @param  array 	   $visibility_caps        Array of capabilities to display in field dropdown.
72
-     * @param  string      $field_type  Type of field options to render (`field` or `widget`)
73 72
      * @param  string      $template_id Table slug
74 73
      * @param  float       $field_id    GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by`
75 74
      * @param  string      $context     What context are we in? Example: `single` or `directory`
Please login to merge, or discard this patch.
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -10,175 +10,175 @@
 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_Admin {
18 18
 
19
-    protected $loader;
19
+	protected $loader;
20 20
 
21
-    function __construct( GravityView_Edit_Entry $loader ) {
22
-        $this->loader = $loader;
23
-    }
21
+	function __construct( GravityView_Edit_Entry $loader ) {
22
+		$this->loader = $loader;
23
+	}
24 24
 
25
-    function load() {
26
-
27
-        if( !is_admin() ) {
28
-            return;
29
-        }
30
-
31
-        // Add Edit Link as a default field, outside those set in the Gravity Form form
32
-        add_filter( 'gravityview_entry_default_fields', array( $this, 'add_default_field' ), 10, 3 );
33
-
34
-        // For the Edit Entry Link, you don't want visible to all users.
35
-        add_filter( 'gravityview_field_visibility_caps', array( $this, 'modify_visibility_caps' ), 10, 5 );
25
+	function load() {
26
+
27
+		if( !is_admin() ) {
28
+			return;
29
+		}
30
+
31
+		// Add Edit Link as a default field, outside those set in the Gravity Form form
32
+		add_filter( 'gravityview_entry_default_fields', array( $this, 'add_default_field' ), 10, 3 );
33
+
34
+		// For the Edit Entry Link, you don't want visible to all users.
35
+		add_filter( 'gravityview_field_visibility_caps', array( $this, 'modify_visibility_caps' ), 10, 5 );
36 36
 
37
-        // Modify the field options based on the name of the field type
38
-        add_filter( 'gravityview_template_edit_link_options', array( $this, 'edit_link_field_options' ), 10, 5 );
37
+		// Modify the field options based on the name of the field type
38
+		add_filter( 'gravityview_template_edit_link_options', array( $this, 'edit_link_field_options' ), 10, 5 );
39 39
 
40
-        // add tooltips
41
-        add_filter( 'gravityview_tooltips', array( $this, 'tooltips') );
42
-
43
-        // custom fields' options for zone EDIT
44
-        add_filter( 'gravityview_template_field_options', array( $this, 'field_options' ), 10, 5 );
45
-    }
46
-
47
-    /**
48
-     * Add Edit Link as a default field, outside those set in the Gravity Form form
49
-     * @param array $entry_default_fields Existing fields
50
-     * @param  string|array $form form_ID or form object
51
-     * @param  string $zone   Either 'single', 'directory', 'header', 'footer'
52
-     */
53
-    function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) {
54
-
55
-        if( $zone !== 'edit' ) {
56
-
57
-            $entry_default_fields['edit_link'] = array(
58
-                'label' => __('Edit Entry', 'gravityview'),
59
-                'type' => 'edit_link',
60
-                'desc'	=> __('A link to edit the entry. Visible based on View settings.', 'gravityview'),
61
-            );
62
-
63
-        }
64
-
65
-        return $entry_default_fields;
66
-    }
67
-
68
-    /**
69
-     * Change wording for the Edit context to read Entry Creator
70
-     *
71
-     * @param  array 	   $visibility_caps        Array of capabilities to display in field dropdown.
72
-     * @param  string      $field_type  Type of field options to render (`field` or `widget`)
73
-     * @param  string      $template_id Table slug
74
-     * @param  float       $field_id    GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by`
75
-     * @param  string      $context     What context are we in? Example: `single` or `directory`
76
-     * @param  string      $input_type  (textarea, list, select, etc.)
77
-     * @return array                   Array of field options with `label`, `value`, `type`, `default` keys
78
-     */
79
-    function modify_visibility_caps( $visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '' ) {
80
-
81
-        $caps = $visibility_caps;
82
-
83
-        // If we're configuring fields in the edit context, we want a limited selection
84
-        if( $context === 'edit' ) {
85
-
86
-            // Remove other built-in caps.
87
-            unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] );
88
-
89
-            $caps['read'] = _x('Entry Creator','User capability', 'gravityview');
90
-        }
91
-
92
-        return $caps;
93
-    }
94
-
95
-    /**
96
-     * Add "Edit Link Text" setting to the edit_link field settings
97
-     * @param  [type] $field_options [description]
98
-     * @param  [type] $template_id   [description]
99
-     * @param  [type] $field_id      [description]
100
-     * @param  [type] $context       [description]
101
-     * @param  [type] $input_type    [description]
102
-     * @return [type]                [description]
103
-     */
104
-    function edit_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
105
-
106
-        // Always a link, never a filter
107
-        unset( $field_options['show_as_link'], $field_options['search_filter'] );
108
-
109
-        // Edit Entry link should only appear to visitors capable of editing entries
110
-        unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] );
111
-
112
-        $add_option['edit_link'] = array(
113
-            'type' => 'text',
114
-            'label' => __( 'Edit Link Text', 'gravityview' ),
115
-            'desc' => NULL,
116
-            'value' => __('Edit Entry', 'gravityview'),
117
-            'merge_tags' => true,
118
-        );
119
-
120
-        return array_merge( $add_option, $field_options );
121
-    }
122
-
123
-    /**
124
-     * Add tooltips
125
-     * @param  array $tooltips Existing tooltips
126
-     * @return array           Modified tooltips
127
-     */
128
-    function tooltips( $tooltips ) {
129
-
130
-        $return = $tooltips;
131
-
132
-        $return['allow_edit_cap'] = array(
133
-            'title' => __('Limiting Edit Access', 'gravityview'),
134
-            'value' => __('Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gravityview'),
135
-        );
136
-
137
-        return $return;
138
-    }
139
-
140
-    /**
141
-     * Manipulate the fields' options for the EDIT ENTRY screen
142
-     * @param  [type] $field_options [description]
143
-     * @param  [type] $template_id   [description]
144
-     * @param  [type] $field_id      [description]
145
-     * @param  [type] $context       [description]
146
-     * @param  [type] $input_type    [description]
147
-     * @return [type]                [description]
148
-     */
149
-    function field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
150
-
151
-        // We only want to modify the settings for the edit context
152
-        if( 'edit' !== $context ) {
153
-
154
-            /**
155
-             * @since 1.8.4
156
-             */
157
-            $field_options['new_window'] = array(
158
-                'type' => 'checkbox',
159
-                'label' => __( 'Open link in a new tab or window?', 'gravityview' ),
160
-                'value' => false,
161
-            );
162
-
163
-            return $field_options;
164
-        }
165
-
166
-        //  Entry field is only for logged in users
167
-        unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] );
168
-
169
-        $add_options = array(
170
-            'allow_edit_cap' => array(
171
-                'type' => 'select',
172
-                'label' => __( 'Make field editable to:', 'gravityview' ),
173
-                'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ),
174
-                'tooltip' => 'allow_edit_cap',
175
-                'class' => 'widefat',
176
-                'value' => 'read', // Default: entry creator
177
-            ),
178
-        );
179
-
180
-        return array_merge( $field_options, $add_options );
181
-    }
40
+		// add tooltips
41
+		add_filter( 'gravityview_tooltips', array( $this, 'tooltips') );
42
+
43
+		// custom fields' options for zone EDIT
44
+		add_filter( 'gravityview_template_field_options', array( $this, 'field_options' ), 10, 5 );
45
+	}
46
+
47
+	/**
48
+	 * Add Edit Link as a default field, outside those set in the Gravity Form form
49
+	 * @param array $entry_default_fields Existing fields
50
+	 * @param  string|array $form form_ID or form object
51
+	 * @param  string $zone   Either 'single', 'directory', 'header', 'footer'
52
+	 */
53
+	function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) {
54
+
55
+		if( $zone !== 'edit' ) {
56
+
57
+			$entry_default_fields['edit_link'] = array(
58
+				'label' => __('Edit Entry', 'gravityview'),
59
+				'type' => 'edit_link',
60
+				'desc'	=> __('A link to edit the entry. Visible based on View settings.', 'gravityview'),
61
+			);
62
+
63
+		}
64
+
65
+		return $entry_default_fields;
66
+	}
67
+
68
+	/**
69
+	 * Change wording for the Edit context to read Entry Creator
70
+	 *
71
+	 * @param  array 	   $visibility_caps        Array of capabilities to display in field dropdown.
72
+	 * @param  string      $field_type  Type of field options to render (`field` or `widget`)
73
+	 * @param  string      $template_id Table slug
74
+	 * @param  float       $field_id    GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by`
75
+	 * @param  string      $context     What context are we in? Example: `single` or `directory`
76
+	 * @param  string      $input_type  (textarea, list, select, etc.)
77
+	 * @return array                   Array of field options with `label`, `value`, `type`, `default` keys
78
+	 */
79
+	function modify_visibility_caps( $visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '' ) {
80
+
81
+		$caps = $visibility_caps;
82
+
83
+		// If we're configuring fields in the edit context, we want a limited selection
84
+		if( $context === 'edit' ) {
85
+
86
+			// Remove other built-in caps.
87
+			unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] );
88
+
89
+			$caps['read'] = _x('Entry Creator','User capability', 'gravityview');
90
+		}
91
+
92
+		return $caps;
93
+	}
94
+
95
+	/**
96
+	 * Add "Edit Link Text" setting to the edit_link field settings
97
+	 * @param  [type] $field_options [description]
98
+	 * @param  [type] $template_id   [description]
99
+	 * @param  [type] $field_id      [description]
100
+	 * @param  [type] $context       [description]
101
+	 * @param  [type] $input_type    [description]
102
+	 * @return [type]                [description]
103
+	 */
104
+	function edit_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
105
+
106
+		// Always a link, never a filter
107
+		unset( $field_options['show_as_link'], $field_options['search_filter'] );
108
+
109
+		// Edit Entry link should only appear to visitors capable of editing entries
110
+		unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] );
111
+
112
+		$add_option['edit_link'] = array(
113
+			'type' => 'text',
114
+			'label' => __( 'Edit Link Text', 'gravityview' ),
115
+			'desc' => NULL,
116
+			'value' => __('Edit Entry', 'gravityview'),
117
+			'merge_tags' => true,
118
+		);
119
+
120
+		return array_merge( $add_option, $field_options );
121
+	}
122
+
123
+	/**
124
+	 * Add tooltips
125
+	 * @param  array $tooltips Existing tooltips
126
+	 * @return array           Modified tooltips
127
+	 */
128
+	function tooltips( $tooltips ) {
129
+
130
+		$return = $tooltips;
131
+
132
+		$return['allow_edit_cap'] = array(
133
+			'title' => __('Limiting Edit Access', 'gravityview'),
134
+			'value' => __('Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gravityview'),
135
+		);
136
+
137
+		return $return;
138
+	}
139
+
140
+	/**
141
+	 * Manipulate the fields' options for the EDIT ENTRY screen
142
+	 * @param  [type] $field_options [description]
143
+	 * @param  [type] $template_id   [description]
144
+	 * @param  [type] $field_id      [description]
145
+	 * @param  [type] $context       [description]
146
+	 * @param  [type] $input_type    [description]
147
+	 * @return [type]                [description]
148
+	 */
149
+	function field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
150
+
151
+		// We only want to modify the settings for the edit context
152
+		if( 'edit' !== $context ) {
153
+
154
+			/**
155
+			 * @since 1.8.4
156
+			 */
157
+			$field_options['new_window'] = array(
158
+				'type' => 'checkbox',
159
+				'label' => __( 'Open link in a new tab or window?', 'gravityview' ),
160
+				'value' => false,
161
+			);
162
+
163
+			return $field_options;
164
+		}
165
+
166
+		//  Entry field is only for logged in users
167
+		unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] );
168
+
169
+		$add_options = array(
170
+			'allow_edit_cap' => array(
171
+				'type' => 'select',
172
+				'label' => __( 'Make field editable to:', 'gravityview' ),
173
+				'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ),
174
+				'tooltip' => 'allow_edit_cap',
175
+				'class' => 'widefat',
176
+				'value' => 'read', // Default: entry creator
177
+			),
178
+		);
179
+
180
+		return array_merge( $field_options, $add_options );
181
+	}
182 182
 
183 183
 
184 184
 } // end class
185 185
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 
25 25
     function load() {
26 26
 
27
-        if( !is_admin() ) {
27
+        if ( ! is_admin() ) {
28 28
             return;
29 29
         }
30 30
 
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
         add_filter( 'gravityview_template_edit_link_options', array( $this, 'edit_link_field_options' ), 10, 5 );
39 39
 
40 40
         // add tooltips
41
-        add_filter( 'gravityview_tooltips', array( $this, 'tooltips') );
41
+        add_filter( 'gravityview_tooltips', array( $this, 'tooltips' ) );
42 42
 
43 43
         // custom fields' options for zone EDIT
44 44
         add_filter( 'gravityview_template_field_options', array( $this, 'field_options' ), 10, 5 );
@@ -52,12 +52,12 @@  discard block
 block discarded – undo
52 52
      */
53 53
     function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) {
54 54
 
55
-        if( $zone !== 'edit' ) {
55
+        if ( $zone !== 'edit' ) {
56 56
 
57
-            $entry_default_fields['edit_link'] = array(
58
-                'label' => __('Edit Entry', 'gravityview'),
57
+            $entry_default_fields[ 'edit_link' ] = array(
58
+                'label' => __( 'Edit Entry', 'gravityview' ),
59 59
                 'type' => 'edit_link',
60
-                'desc'	=> __('A link to edit the entry. Visible based on View settings.', 'gravityview'),
60
+                'desc'	=> __( 'A link to edit the entry. Visible based on View settings.', 'gravityview' ),
61 61
             );
62 62
 
63 63
         }
@@ -81,12 +81,12 @@  discard block
 block discarded – undo
81 81
         $caps = $visibility_caps;
82 82
 
83 83
         // If we're configuring fields in the edit context, we want a limited selection
84
-        if( $context === 'edit' ) {
84
+        if ( $context === 'edit' ) {
85 85
 
86 86
             // Remove other built-in caps.
87
-            unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] );
87
+            unset( $caps[ 'publish_posts' ], $caps[ 'gravityforms_view_entries' ], $caps[ 'delete_others_posts' ] );
88 88
 
89
-            $caps['read'] = _x('Entry Creator','User capability', 'gravityview');
89
+            $caps[ 'read' ] = _x( 'Entry Creator', 'User capability', 'gravityview' );
90 90
         }
91 91
 
92 92
         return $caps;
@@ -104,16 +104,16 @@  discard block
 block discarded – undo
104 104
     function edit_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
105 105
 
106 106
         // Always a link, never a filter
107
-        unset( $field_options['show_as_link'], $field_options['search_filter'] );
107
+        unset( $field_options[ 'show_as_link' ], $field_options[ 'search_filter' ] );
108 108
 
109 109
         // Edit Entry link should only appear to visitors capable of editing entries
110
-        unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] );
110
+        unset( $field_options[ 'only_loggedin' ], $field_options[ 'only_loggedin_cap' ] );
111 111
 
112
-        $add_option['edit_link'] = array(
112
+        $add_option[ 'edit_link' ] = array(
113 113
             'type' => 'text',
114 114
             'label' => __( 'Edit Link Text', 'gravityview' ),
115 115
             'desc' => NULL,
116
-            'value' => __('Edit Entry', 'gravityview'),
116
+            'value' => __( 'Edit Entry', 'gravityview' ),
117 117
             'merge_tags' => true,
118 118
         );
119 119
 
@@ -129,9 +129,9 @@  discard block
 block discarded – undo
129 129
 
130 130
         $return = $tooltips;
131 131
 
132
-        $return['allow_edit_cap'] = array(
133
-            'title' => __('Limiting Edit Access', 'gravityview'),
134
-            'value' => __('Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gravityview'),
132
+        $return[ 'allow_edit_cap' ] = array(
133
+            'title' => __( 'Limiting Edit Access', 'gravityview' ),
134
+            'value' => __( 'Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gravityview' ),
135 135
         );
136 136
 
137 137
         return $return;
@@ -149,12 +149,12 @@  discard block
 block discarded – undo
149 149
     function field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
150 150
 
151 151
         // We only want to modify the settings for the edit context
152
-        if( 'edit' !== $context ) {
152
+        if ( 'edit' !== $context ) {
153 153
 
154 154
             /**
155 155
              * @since 1.8.4
156 156
              */
157
-            $field_options['new_window'] = array(
157
+            $field_options[ 'new_window' ] = array(
158 158
                 'type' => 'checkbox',
159 159
                 'label' => __( 'Open link in a new tab or window?', 'gravityview' ),
160 160
                 'value' => false,
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
         }
165 165
 
166 166
         //  Entry field is only for logged in users
167
-        unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] );
167
+        unset( $field_options[ 'only_loggedin' ], $field_options[ 'only_loggedin_cap' ] );
168 168
 
169 169
         $add_options = array(
170 170
             'allow_edit_cap' => array(
Please login to merge, or discard this patch.
includes/extensions/edit-entry/class-edit-entry-render.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1249,7 +1249,7 @@
 block discarded – undo
1249 1249
     /**
1250 1250
      * Override GF Form field properties with the ones defined on the View
1251 1251
      * @param  GF_Field $field GF Form field object
1252
-     * @param  array $setting  GV field options
1252
+     * @param  array $field_setting  GV field options
1253 1253
      * @since  1.5
1254 1254
      * @return array
1255 1255
      */
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
 
614 614
             $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) );
615 615
 
616
-            if( ! $this->is_valid ){
616
+            if( ! $this->is_valid ) {
617 617
 
618 618
                 // Keeping this compatible with Gravity Forms.
619 619
                 $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>";
@@ -1620,9 +1620,7 @@  discard block
 block discarded – undo
1620 1620
         // Verify
1621 1621
         else if( ! $this->is_edit_entry() ) {
1622 1622
             $valid = false;
1623
-        }
1624
-
1625
-        else {
1623
+        } else {
1626 1624
             $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key );
1627 1625
         }
1628 1626
 
Please login to merge, or discard this patch.
Indentation   +1648 added lines, -1648 removed lines patch added patch discarded remove patch
@@ -10,21 +10,21 @@  discard block
 block discarded – undo
10 10
  */
11 11
 
12 12
 if ( ! defined( 'WPINC' ) ) {
13
-    die;
13
+	die;
14 14
 }
15 15
 
16 16
 
17 17
 class GravityView_Edit_Entry_Render {
18 18
 
19
-    /**
20
-     * @var GravityView_Edit_Entry
21
-     */
22
-    protected $loader;
19
+	/**
20
+	 * @var GravityView_Edit_Entry
21
+	 */
22
+	protected $loader;
23 23
 
24 24
 	/**
25 25
 	 * @var string String used to generate unique nonce for the entry/form/view combination. Allows access to edit page.
26 26
 	 */
27
-    static $nonce_key;
27
+	static $nonce_key;
28 28
 
29 29
 	/**
30 30
 	 * @since 1.9
@@ -44,12 +44,12 @@  discard block
 block discarded – undo
44 44
 	 */
45 45
 	private static $supports_product_fields = false;
46 46
 
47
-    /**
48
-     * Gravity Forms entry array
49
-     *
50
-     * @var array
51
-     */
52
-    var $entry;
47
+	/**
48
+	 * Gravity Forms entry array
49
+	 *
50
+	 * @var array
51
+	 */
52
+	var $entry;
53 53
 
54 54
 	/**
55 55
 	 * Gravity Forms entry array (it won't get changed during this class lifecycle)
@@ -58,135 +58,135 @@  discard block
 block discarded – undo
58 58
 	 */
59 59
 	private static $original_entry = array();
60 60
 
61
-    /**
62
-     * Gravity Forms form array (GravityView modifies the content through this class lifecycle)
63
-     *
64
-     * @var array
65
-     */
66
-    var $form;
67
-
68
-    /**
69
-     * Gravity Forms form array (it won't get changed during this class lifecycle)
70
-     * @since 1.16.2.1
71
-     * @var array
72
-     */
73
-    private static $original_form;
74
-
75
-    /**
76
-     * Gravity Forms form array after the form validation process
77
-     * @since 1.13
78
-     * @var array
79
-     */
80
-    var $form_after_validation = null;
81
-
82
-    /**
83
-     * Hold an array of GF field objects that have calculation rules
84
-     * @var array
85
-     */
86
-    var $fields_with_calculation = array();
87
-
88
-    /**
89
-     * Hold an array of GF field objects with type 'total'
90
-     * @var array
91
-     */
92
-    var $total_fields = array();
93
-
94
-    /**
95
-     * Gravity Forms form id
96
-     *
97
-     * @var int
98
-     */
99
-    var $form_id;
100
-
101
-    /**
102
-     * ID of the current view
103
-     *
104
-     * @var int
105
-     */
106
-    var $view_id;
107
-
108
-    /**
109
-     * Updated entry is valid (GF Validation object)
110
-     *
111
-     * @var array
112
-     */
113
-    var $is_valid = NULL;
114
-
115
-    function __construct( GravityView_Edit_Entry $loader ) {
116
-        $this->loader = $loader;
117
-    }
118
-
119
-    function load() {
120
-
121
-        /** @define "GRAVITYVIEW_DIR" "../../../" */
122
-        include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' );
123
-
124
-        // Don't display an embedded form when editing an entry
125
-        add_action( 'wp_head', array( $this, 'prevent_render_form' ) );
126
-        add_action( 'wp_footer', array( $this, 'prevent_render_form' ) );
127
-
128
-        // Stop Gravity Forms processing what is ours!
129
-        add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 );
130
-
131
-        add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') );
132
-
133
-        add_action( 'gravityview_edit_entry', array( $this, 'init' ) );
134
-
135
-        // Disable conditional logic if needed (since 1.9)
136
-        add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 );
137
-
138
-        // Make sure GF doesn't validate max files (since 1.9)
139
-        add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 );
140
-
141
-        // Add fields expected by GFFormDisplay::validate()
142
-        add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') );
143
-
144
-    }
145
-
146
-    /**
147
-     * Don't show any forms embedded on a page when GravityView is in Edit Entry mode
148
-     *
149
-     * Adds a `__return_empty_string` filter on the Gravity Forms shortcode on the `wp_head` action
150
-     * And then removes it on the `wp_footer` action
151
-     *
152
-     * @since 1.16.1
153
-     *
154
-     * @return void
155
-     */
156
-    function prevent_render_form() {
157
-        if( $this->is_edit_entry() ) {
158
-            if( 'wp_head' === current_filter() ) {
159
-                add_filter( 'gform_shortcode_form', '__return_empty_string' );
160
-            } else {
161
-                remove_filter( 'gform_shortcode_form', '__return_empty_string' );
162
-            }
163
-        }
164
-    }
165
-
166
-    /**
167
-     * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms
168
-     * backend form, we need to prevent them from saving twice.
169
-     * @return void
170
-     */
171
-    function prevent_maybe_process_form() {
172
-
173
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
174
-
175
-        if( $this->is_edit_entry_submission() && $this->verify_nonce() ) {
176
-            remove_action( 'wp',  array( 'RGForms', 'maybe_process_form'), 9 );
177
-        }
178
-    }
179
-
180
-    /**
181
-     * Is the current page an Edit Entry page?
182
-     * @return boolean
183
-     */
184
-    public function is_edit_entry() {
185
-
186
-        $gf_page = function_exists('rgpost') && ( 'entry' === rgget( 'view' ) && isset( $_GET['edit'] ) );
187
-
188
-        return $gf_page;
189
-    }
61
+	/**
62
+	 * Gravity Forms form array (GravityView modifies the content through this class lifecycle)
63
+	 *
64
+	 * @var array
65
+	 */
66
+	var $form;
67
+
68
+	/**
69
+	 * Gravity Forms form array (it won't get changed during this class lifecycle)
70
+	 * @since 1.16.2.1
71
+	 * @var array
72
+	 */
73
+	private static $original_form;
74
+
75
+	/**
76
+	 * Gravity Forms form array after the form validation process
77
+	 * @since 1.13
78
+	 * @var array
79
+	 */
80
+	var $form_after_validation = null;
81
+
82
+	/**
83
+	 * Hold an array of GF field objects that have calculation rules
84
+	 * @var array
85
+	 */
86
+	var $fields_with_calculation = array();
87
+
88
+	/**
89
+	 * Hold an array of GF field objects with type 'total'
90
+	 * @var array
91
+	 */
92
+	var $total_fields = array();
93
+
94
+	/**
95
+	 * Gravity Forms form id
96
+	 *
97
+	 * @var int
98
+	 */
99
+	var $form_id;
100
+
101
+	/**
102
+	 * ID of the current view
103
+	 *
104
+	 * @var int
105
+	 */
106
+	var $view_id;
107
+
108
+	/**
109
+	 * Updated entry is valid (GF Validation object)
110
+	 *
111
+	 * @var array
112
+	 */
113
+	var $is_valid = NULL;
114
+
115
+	function __construct( GravityView_Edit_Entry $loader ) {
116
+		$this->loader = $loader;
117
+	}
118
+
119
+	function load() {
120
+
121
+		/** @define "GRAVITYVIEW_DIR" "../../../" */
122
+		include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' );
123
+
124
+		// Don't display an embedded form when editing an entry
125
+		add_action( 'wp_head', array( $this, 'prevent_render_form' ) );
126
+		add_action( 'wp_footer', array( $this, 'prevent_render_form' ) );
127
+
128
+		// Stop Gravity Forms processing what is ours!
129
+		add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 );
130
+
131
+		add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') );
132
+
133
+		add_action( 'gravityview_edit_entry', array( $this, 'init' ) );
134
+
135
+		// Disable conditional logic if needed (since 1.9)
136
+		add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 );
137
+
138
+		// Make sure GF doesn't validate max files (since 1.9)
139
+		add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 );
140
+
141
+		// Add fields expected by GFFormDisplay::validate()
142
+		add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') );
143
+
144
+	}
145
+
146
+	/**
147
+	 * Don't show any forms embedded on a page when GravityView is in Edit Entry mode
148
+	 *
149
+	 * Adds a `__return_empty_string` filter on the Gravity Forms shortcode on the `wp_head` action
150
+	 * And then removes it on the `wp_footer` action
151
+	 *
152
+	 * @since 1.16.1
153
+	 *
154
+	 * @return void
155
+	 */
156
+	function prevent_render_form() {
157
+		if( $this->is_edit_entry() ) {
158
+			if( 'wp_head' === current_filter() ) {
159
+				add_filter( 'gform_shortcode_form', '__return_empty_string' );
160
+			} else {
161
+				remove_filter( 'gform_shortcode_form', '__return_empty_string' );
162
+			}
163
+		}
164
+	}
165
+
166
+	/**
167
+	 * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms
168
+	 * backend form, we need to prevent them from saving twice.
169
+	 * @return void
170
+	 */
171
+	function prevent_maybe_process_form() {
172
+
173
+		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
174
+
175
+		if( $this->is_edit_entry_submission() && $this->verify_nonce() ) {
176
+			remove_action( 'wp',  array( 'RGForms', 'maybe_process_form'), 9 );
177
+		}
178
+	}
179
+
180
+	/**
181
+	 * Is the current page an Edit Entry page?
182
+	 * @return boolean
183
+	 */
184
+	public function is_edit_entry() {
185
+
186
+		$gf_page = function_exists('rgpost') && ( 'entry' === rgget( 'view' ) && isset( $_GET['edit'] ) );
187
+
188
+		return $gf_page;
189
+	}
190 190
 
191 191
 	/**
192 192
 	 * Is the current page an Edit Entry page?
@@ -197,578 +197,578 @@  discard block
 block discarded – undo
197 197
 		return !empty( $_POST[ self::$nonce_field ] );
198 198
 	}
199 199
 
200
-    /**
201
-     * When Edit entry view is requested setup the vars
202
-     */
203
-    function setup_vars() {
204
-        $gravityview_view = GravityView_View::getInstance();
200
+	/**
201
+	 * When Edit entry view is requested setup the vars
202
+	 */
203
+	function setup_vars() {
204
+		$gravityview_view = GravityView_View::getInstance();
205
+
205 206
 
207
+		$entries = $gravityview_view->getEntries();
208
+		self::$original_entry = $entries[0];
209
+		$this->entry = $entries[0];
206 210
 
207
-        $entries = $gravityview_view->getEntries();
208
-	    self::$original_entry = $entries[0];
209
-	    $this->entry = $entries[0];
211
+		self::$original_form = $gravityview_view->getForm();
212
+		$this->form = $gravityview_view->getForm();
213
+		$this->form_id = $gravityview_view->getFormId();
214
+		$this->view_id = $gravityview_view->getViewId();
210 215
 
211
-        self::$original_form = $gravityview_view->getForm();
212
-        $this->form = $gravityview_view->getForm();
213
-        $this->form_id = $gravityview_view->getFormId();
214
-        $this->view_id = $gravityview_view->getViewId();
216
+		self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] );
217
+	}
215 218
 
216
-        self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] );
217
-    }
218 219
 
220
+	/**
221
+	 * Load required files and trigger edit flow
222
+	 *
223
+	 * Run when the is_edit_entry returns true.
224
+	 *
225
+	 * @param GravityView_View_Data $gv_data GravityView Data object
226
+	 * @return void
227
+	 */
228
+	function init( $gv_data ) {
219 229
 
220
-    /**
221
-     * Load required files and trigger edit flow
222
-     *
223
-     * Run when the is_edit_entry returns true.
224
-     *
225
-     * @param GravityView_View_Data $gv_data GravityView Data object
226
-     * @return void
227
-     */
228
-    function init( $gv_data ) {
230
+		require_once( GFCommon::get_base_path() . '/form_display.php' );
231
+		require_once( GFCommon::get_base_path() . '/entry_detail.php' );
229 232
 
230
-        require_once( GFCommon::get_base_path() . '/form_display.php' );
231
-        require_once( GFCommon::get_base_path() . '/entry_detail.php' );
233
+		$this->setup_vars();
232 234
 
233
-        $this->setup_vars();
235
+		// Multiple Views embedded, don't proceed if nonce fails
236
+		if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) {
237
+			return;
238
+		}
234 239
 
235
-        // Multiple Views embedded, don't proceed if nonce fails
236
-        if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) {
237
-            return;
238
-        }
240
+		// Sorry, you're not allowed here.
241
+		if( false === $this->user_can_edit_entry( true ) ) {
242
+			return;
243
+		}
239 244
 
240
-        // Sorry, you're not allowed here.
241
-        if( false === $this->user_can_edit_entry( true ) ) {
242
-            return;
243
-        }
245
+		$this->print_scripts();
244 246
 
245
-        $this->print_scripts();
247
+		$this->process_save();
246 248
 
247
-        $this->process_save();
249
+		$this->edit_entry_form();
248 250
 
249
-        $this->edit_entry_form();
251
+	}
250 252
 
251
-    }
252 253
 
254
+	/**
255
+	 * Force Gravity Forms to output scripts as if it were in the admin
256
+	 * @return void
257
+	 */
258
+	function print_scripts() {
259
+		$gravityview_view = GravityView_View::getInstance();
253 260
 
254
-    /**
255
-     * Force Gravity Forms to output scripts as if it were in the admin
256
-     * @return void
257
-     */
258
-    function print_scripts() {
259
-        $gravityview_view = GravityView_View::getInstance();
261
+		wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) );
260 262
 
261
-        wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) );
263
+		GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false);
262 264
 
263
-        GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false);
265
+		// Sack is required for images
266
+		wp_print_scripts( array( 'sack', 'gform_gravityforms' ) );
267
+	}
264 268
 
265
-        // Sack is required for images
266
-        wp_print_scripts( array( 'sack', 'gform_gravityforms' ) );
267
-    }
268 269
 
270
+	/**
271
+	 * Process edit entry form save
272
+	 */
273
+	function process_save() {
269 274
 
270
-    /**
271
-     * Process edit entry form save
272
-     */
273
-    function process_save() {
275
+		if( empty( $_POST ) ) {
276
+			return;
277
+		}
274 278
 
275
-        if( empty( $_POST ) ) {
276
-            return;
277
-        }
279
+		// Make sure the entry, view, and form IDs are all correct
280
+		$valid = $this->verify_nonce();
278 281
 
279
-        // Make sure the entry, view, and form IDs are all correct
280
-        $valid = $this->verify_nonce();
282
+		if( !$valid ) {
283
+			do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' );
284
+			return;
285
+		}
281 286
 
282
-        if( !$valid ) {
283
-            do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' );
284
-            return;
285
-        }
287
+		if( $this->entry['id'] !== $_POST['lid'] ) {
288
+			do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' );
289
+			return;
290
+		}
286 291
 
287
-        if( $this->entry['id'] !== $_POST['lid'] ) {
288
-            do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' );
289
-            return;
290
-        }
292
+		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
291 293
 
292
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
294
+		$this->process_save_process_files( $this->form_id );
293 295
 
294
-        $this->process_save_process_files( $this->form_id );
296
+		$this->validate();
295 297
 
296
-        $this->validate();
298
+		if( $this->is_valid ) {
297 299
 
298
-        if( $this->is_valid ) {
300
+			do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' );
299 301
 
300
-            do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' );
302
+			/**
303
+			 * @hack This step is needed to unset the adminOnly from form fields, to add the calculation fields
304
+			 */
305
+			$form = $this->form_prepare_for_save();
301 306
 
302
-            /**
303
-             * @hack This step is needed to unset the adminOnly from form fields, to add the calculation fields
304
-             */
305
-            $form = $this->form_prepare_for_save();
307
+			/**
308
+			 * @hack to avoid the capability validation of the method save_lead for GF 1.9+
309
+			 */
310
+			unset( $_GET['page'] );
306 311
 
307
-            /**
308
-             * @hack to avoid the capability validation of the method save_lead for GF 1.9+
309
-             */
310
-            unset( $_GET['page'] );
312
+			GFFormsModel::save_lead( $form, $this->entry );
311 313
 
312
-            GFFormsModel::save_lead( $form, $this->entry );
314
+			// If there's a post associated with the entry, process post fields
315
+			if( !empty( $this->entry['post_id'] ) ) {
316
+				$this->maybe_update_post_fields( $form );
317
+			}
313 318
 
314
-            // If there's a post associated with the entry, process post fields
315
-            if( !empty( $this->entry['post_id'] ) ) {
316
-                $this->maybe_update_post_fields( $form );
317
-            }
319
+			// Process calculation fields
320
+			$this->update_calculation_fields();
318 321
 
319
-            // Process calculation fields
320
-            $this->update_calculation_fields();
322
+			// Perform actions normally performed after updating a lead
323
+			$this->after_update();
321 324
 
322
-            // Perform actions normally performed after updating a lead
323
-            $this->after_update();
325
+			/**
326
+			 * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry
327
+			 * @param array $form Gravity Forms form array
328
+			 * @param string $entry_id Numeric ID of the entry that was updated
329
+			 */
330
+			do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] );
331
+		}
324 332
 
325
-            /**
326
-             * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry
327
-             * @param array $form Gravity Forms form array
328
-             * @param string $entry_id Numeric ID of the entry that was updated
329
-             */
330
-            do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] );
331
-        }
333
+	} // process_save
332 334
 
333
-    } // process_save
334 335
 
336
+	/**
337
+	 * Have GF handle file uploads
338
+	 *
339
+	 * Copy of code from GFFormDisplay::process_form()
340
+	 *
341
+	 * @param int $form_id
342
+	 */
343
+	function process_save_process_files( $form_id ) {
335 344
 
336
-    /**
337
-     * Have GF handle file uploads
338
-     *
339
-     * Copy of code from GFFormDisplay::process_form()
340
-     *
341
-     * @param int $form_id
342
-     */
343
-    function process_save_process_files( $form_id ) {
345
+		//Loading files that have been uploaded to temp folder
346
+		$files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) );
347
+		if ( ! is_array( $files ) ) {
348
+			$files = array();
349
+		}
344 350
 
345
-        //Loading files that have been uploaded to temp folder
346
-        $files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) );
347
-        if ( ! is_array( $files ) ) {
348
-            $files = array();
349
-        }
351
+		RGFormsModel::$uploaded_files[ $form_id ] = $files;
352
+	}
350 353
 
351
-        RGFormsModel::$uploaded_files[ $form_id ] = $files;
352
-    }
353
-
354
-    /**
355
-     * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView
356
-     * Late validation done on self::custom_validation
357
-     *
358
-     * @param $plupload_init array Plupload settings
359
-     * @param $form_id
360
-     * @param $instance
361
-     * @return mixed
362
-     */
363
-    public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) {
364
-        if( ! $this->is_edit_entry() ) {
365
-            return $plupload_init;
366
-        }
367
-
368
-        $plupload_init['gf_vars']['max_files'] = 0;
369
-
370
-        return $plupload_init;
371
-    }
372
-
373
-
374
-    /**
375
-     * Unset adminOnly and convert field input key to string
376
-     * @return array $form
377
-     */
378
-    private function form_prepare_for_save() {
379
-
380
-        $form = $this->form;
381
-
382
-        foreach( $form['fields'] as $k => &$field ) {
383
-
384
-            // Remove the fields with calculation formulas before save to avoid conflicts with GF logic
385
-            // @since 1.16.3
386
-            if( $field->has_calculation() ) {
387
-                unset( $form['fields'][ $k ] );
388
-            }
389
-
390
-            $field->adminOnly = false;
391
-
392
-            if( isset( $field->inputs ) && is_array( $field->inputs ) ) {
393
-                foreach( $field->inputs as $key => $input ) {
394
-                    $field->inputs[ $key ][ 'id' ] = (string)$input['id'];
395
-                }
396
-            }
397
-        }
398
-
399
-        return $form;
400
-    }
401
-
402
-    private function update_calculation_fields() {
403
-
404
-        $form = self::$original_form;
405
-        $update = false;
406
-
407
-        // get the most up to date entry values
408
-        $entry = GFAPI::get_entry( $this->entry['id'] );
409
-
410
-        if( !empty( $this->fields_with_calculation ) ) {
411
-            $update = true;
412
-            foreach ( $this->fields_with_calculation as $calc_field ) {
413
-                $inputs = $calc_field->get_entry_inputs();
414
-                if ( is_array( $inputs ) ) {
415
-                    foreach ( $inputs as $input ) {
416
-                        $input_name = 'input_' . str_replace( '.', '_', $input['id'] );
417
-                        $entry[ strval( $input['id'] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry );
418
-                    }
419
-                } else {
420
-                    $input_name = 'input_' . str_replace( '.', '_', $calc_field->id);
421
-                    $entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry );
422
-                }
423
-            }
424
-
425
-        }
426
-
427
-        //saving total field as the last field of the form.
428
-        if ( ! empty( $this->total_fields ) ) {
429
-            $update = true;
430
-            foreach ( $this->total_fields as $total_field ) {
431
-                $input_name = 'input_' . str_replace( '.', '_', $total_field->id);
432
-                $entry[ strval( $total_field->id ) ] = RGFormsModel::prepare_value( $form, $total_field, '', $input_name, $entry['id'], $entry );
433
-            }
434
-        }
435
-
436
-        if( $update ) {
437
-
438
-            $return_entry = GFAPI::update_entry( $entry );
439
-
440
-            if( is_wp_error( $return_entry ) ) {
441
-                do_action( 'gravityview_log_error', 'Updating the entry calculation and total fields failed', $return_entry );
442
-            } else {
443
-                do_action( 'gravityview_log_debug', 'Updating the entry calculation and total fields succeeded' );
444
-            }
445
-        }
446
-    }
447
-
448
-    /**
449
-     * Handle updating the Post Image field
450
-     *
451
-     * Sets a new Featured Image if configured in Gravity Forms; otherwise uploads/updates media
452
-     *
453
-     * @since 1.17
454
-     *
455
-     * @uses GFFormsModel::media_handle_upload
456
-     * @uses set_post_thumbnail
457
-     * 
458
-     * @param array $form GF Form array
459
-     * @param GF_Field $field GF Field
460
-     * @param string $field_id Numeric ID of the field
461
-     * @param string $value
462
-     * @param array $entry GF Entry currently being edited
463
-     * @param int $post_id ID of the Post being edited
464
-     *
465
-     * @return mixed|string
466
-     */
467
-    private function update_post_image( $form, $field, $field_id, $value, $entry, $post_id ) {
468
-
469
-        $input_name = 'input_' . $field_id;
470
-
471
-        if ( !empty( $_FILES[ $input_name ]['name'] ) ) {
472
-
473
-            // We have a new image
474
-
475
-            $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'] );
476
-
477
-            $ary = ! empty( $value ) ? explode( '|:|', $value ) : array();
478
-            $img_url = rgar( $ary, 0 );
479
-
480
-            $img_title       = count( $ary ) > 1 ? $ary[1] : '';
481
-            $img_caption     = count( $ary ) > 2 ? $ary[2] : '';
482
-            $img_description = count( $ary ) > 3 ? $ary[3] : '';
483
-
484
-            $image_meta = array(
485
-                'post_excerpt' => $img_caption,
486
-                'post_content' => $img_description,
487
-            );
488
-
489
-            //adding title only if it is not empty. It will default to the file name if it is not in the array
490
-            if ( ! empty( $img_title ) ) {
491
-                $image_meta['post_title'] = $img_title;
492
-            }
493
-
494
-            /**
495
-             * todo: As soon as \GFFormsModel::media_handle_upload becomes a public method, move this call to \GFFormsModel::media_handle_upload and remove the hack from this class.
496
-             * Note: the method became public in GF 1.9.17.7, but we don't require that version yet.
497
-             */
498
-            require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php';
499
-            $media_id = GravityView_GFFormsModel::media_handle_upload( $img_url, $post_id, $image_meta );
500
-
501
-            // is this field set as featured image?
502
-            if ( $media_id && $field->postFeaturedImage ) {
503
-                set_post_thumbnail( $post_id, $media_id );
504
-            }
505
-
506
-        } elseif ( !empty( $_POST[ $input_name ] ) && is_array( $value ) ) {
507
-
508
-            // Same image although the image title, caption or description might have changed
509
-
510
-            $ary = array();
511
-            if( ! empty( $entry[ $field_id ] ) ) {
512
-                $ary = is_array( $entry[ $field_id ] ) ? $entry[ $field_id ] : explode( '|:|', $entry[ $field_id ] );
513
-            }
514
-            $img_url = rgar( $ary, 0 );
515
-
516
-            // is this really the same image or something went wrong ?
517
-            if( $img_url === $_POST[ $input_name ] ) {
518
-
519
-                $img_title       = rgar( $value, $field_id .'.1' );
520
-                $img_caption     = rgar( $value, $field_id .'.4' );
521
-                $img_description = rgar( $value, $field_id .'.7' );
522
-
523
-                $value = ! empty( $img_url ) ? $img_url . "|:|" . $img_title . "|:|" . $img_caption . "|:|" . $img_description : '';
524
-
525
-                if ( $field->postFeaturedImage ) {
526
-
527
-                    $image_meta = array(
528
-                        'ID' => get_post_thumbnail_id( $post_id ),
529
-                        'post_title' => $img_title,
530
-                        'post_excerpt' => $img_caption,
531
-                        'post_content' => $img_description,
532
-                    );
533
-
534
-                    // update image title, caption or description
535
-                    wp_update_post( $image_meta );
536
-                }
537
-            }
538
-
539
-        } else {
540
-
541
-            // if we get here, image was removed or not set.
542
-            $value = '';
543
-
544
-            if ( $field->postFeaturedImage ) {
545
-                delete_post_thumbnail( $post_id );
546
-            }
547
-        }
548
-
549
-        return $value;
550
-    }
551
-
552
-    /**
553
-     * Loop through the fields being edited and if they include Post fields, update the Entry's post object
554
-     *
555
-     * @param array $form Gravity Forms form
556
-     *
557
-     * @return void
558
-     */
559
-    private function maybe_update_post_fields( $form ) {
560
-
561
-        $post_id = $this->entry['post_id'];
562
-
563
-        // Security check
564
-        if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) {
565
-            do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id );
566
-            return;
567
-        }
354
+	/**
355
+	 * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView
356
+	 * Late validation done on self::custom_validation
357
+	 *
358
+	 * @param $plupload_init array Plupload settings
359
+	 * @param $form_id
360
+	 * @param $instance
361
+	 * @return mixed
362
+	 */
363
+	public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) {
364
+		if( ! $this->is_edit_entry() ) {
365
+			return $plupload_init;
366
+		}
568 367
 
569
-        $update_entry = false;
368
+		$plupload_init['gf_vars']['max_files'] = 0;
570 369
 
571
-        $updated_post = $original_post = get_post( $post_id );
370
+		return $plupload_init;
371
+	}
572 372
 
573
-        foreach ( $this->entry as $field_id => $value ) {
574
-
575
-            $field = RGFormsModel::get_field( $form, $field_id );
576
-
577
-            if( ! $field ) {
578
-                continue;
579
-            }
580
-
581
-            if( GFCommon::is_post_field( $field ) && 'post_category' !== $field->type ) {
582
-
583
-                // Get the value of the field, including $_POSTed value
584
-                $value = RGFormsModel::get_field_value( $field );
585
-
586
-                // Use temporary entry variable, to make values available to fill_post_template() and update_post_image()
587
-                $entry_tmp = $this->entry;
588
-                $entry_tmp["{$field_id}"] = $value;
589
-
590
-                switch( $field->type ) {
591
-
592
-                    case 'post_title':
593
-                        $post_title = $value;
594
-                        if( rgar( $form, 'postTitleTemplateEnabled' ) ) {
595
-                            $post_title = $this->fill_post_template( $form['postTitleTemplate'], $form, $entry_tmp );
596
-                        }
597
-                        $updated_post->post_title = $post_title;
598
-                        $updated_post->post_name  = $post_title;
599
-                        unset( $post_title );
600
-                        break;
601
-
602
-                    case 'post_content':
603
-                        $post_content = $value;
604
-                        if( rgar( $form, 'postContentTemplateEnabled' ) ) {
605
-                            $post_content = $this->fill_post_template( $form['postContentTemplate'], $form, $entry_tmp, true );
606
-                        }
607
-                        $updated_post->post_content = $post_content;
608
-                        unset( $post_content );
609
-                        break;
610
-                    case 'post_excerpt':
611
-                        $updated_post->post_excerpt = $value;
612
-                        break;
613
-                    case 'post_tags':
614
-                        wp_set_post_tags( $post_id, $value, false );
615
-                        break;
616
-                    case 'post_category':
617
-                        break;
618
-                    case 'post_custom_field':
619
-                        if( ! empty( $field->customFieldTemplateEnabled ) ) {
620
-                            $value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true );
621
-                        }
622
-
623
-                        $input_type = RGFormsModel::get_input_type( $field );
624
-
625
-                        // Only certain custom field types are supported
626
-                        switch( $input_type ) {
627
-                            case 'fileupload':
628
-                            case 'list':
629
-                            case 'multiselect':
630
-                                if( ! is_string( $value ) ) {
631
-                                    $value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value );
632
-                                }
633
-                            // break; left intentionally out
634
-                            default:
635
-                                update_post_meta( $post_id, $field->postCustomFieldName, $value );
636
-                        }
637
-
638
-                        break;
639
-
640
-                    case 'post_image':
641
-                        $value = $this->update_post_image( $form, $field, $field_id, $value, $this->entry, $post_id );
642
-                        break;
643
-
644
-                }
645
-
646
-                // update entry after
647
-                $this->entry["{$field_id}"] = $value;
648
-
649
-                $update_entry = true;
650
-
651
-                unset( $entry_tmp );
652
-            }
653
-
654
-        }
655
-
656
-        if( $update_entry ) {
657
-
658
-            $return_entry = GFAPI::update_entry( $this->entry );
659
-
660
-            if( is_wp_error( $return_entry ) ) {
661
-               do_action( 'gravityview_log_error', 'Updating the entry post fields failed', array( '$this->entry' => $this->entry, '$return_entry' => $return_entry ) );
662
-            } else {
663
-                do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' );
664
-            }
665
-
666
-        }
667
-
668
-        $return_post = wp_update_post( $updated_post, true );
669
-
670
-        if( is_wp_error( $return_post ) ) {
671
-            $return_post->add_data( $updated_post, '$updated_post' );
672
-            do_action( 'gravityview_log_error', 'Updating the post content failed', compact( 'updated_post', 'return_post' ) );
673
-        } else {
674
-            do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post );
675
-        }
676
-    }
677
-
678
-    /**
679
-     * Convert a field content template into prepared output
680
-     *
681
-     * @uses GravityView_GFFormsModel::get_post_field_images()
682
-     *
683
-     * @since 1.17
684
-     *
685
-     * @param string $template The content template for the field
686
-     * @param array $form Gravity Forms form
687
-     * @param bool $do_shortcode Whether to process shortcode inside content. In GF, only run on Custom Field and Post Content fields
688
-     *
689
-     * @return mixed|string|void
690
-     */
691
-    function fill_post_template( $template, $form, $entry, $do_shortcode = false ) {
692
-
693
-        require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php';
694
-
695
-        $post_images = GravityView_GFFormsModel::get_post_field_images( $form, $entry );
696
-
697
-        //replacing post image variables
698
-        $output = GFCommon::replace_variables_post_image( $template, $post_images, $entry );
699
-
700
-        //replacing all other variables
701
-        $output = GFCommon::replace_variables( $output, $form, $entry, false, false, false );
702
-
703
-        // replace conditional shortcodes
704
-        if( $do_shortcode ) {
705
-            $output = do_shortcode( $output );
706
-        }
707
-
708
-        return $output;
709
-    }
710
-
711
-
712
-    /**
713
-     * Perform actions normally performed after updating a lead
714
-     *
715
-     * @since 1.8
716
-     *
717
-     * @see GFEntryDetail::lead_detail_page()
718
-     *
719
-     * @return void
720
-     */
721
-    function after_update() {
722 373
 
723
-        do_action( 'gform_after_update_entry', $this->form, $this->entry['id'], self::$original_entry );
724
-        do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] );
374
+	/**
375
+	 * Unset adminOnly and convert field input key to string
376
+	 * @return array $form
377
+	 */
378
+	private function form_prepare_for_save() {
725 379
 
726
-        // Re-define the entry now that we've updated it.
727
-        $entry = RGFormsModel::get_lead( $this->entry['id'] );
380
+		$form = $this->form;
728 381
 
729
-        $entry = GFFormsModel::set_entry_meta( $entry, $this->form );
382
+		foreach( $form['fields'] as $k => &$field ) {
730 383
 
731
-        // We need to clear the cache because Gravity Forms caches the field values, which
732
-        // we have just updated.
733
-        foreach ($this->form['fields'] as $key => $field) {
734
-            GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id );
735
-        }
384
+			// Remove the fields with calculation formulas before save to avoid conflicts with GF logic
385
+			// @since 1.16.3
386
+			if( $field->has_calculation() ) {
387
+				unset( $form['fields'][ $k ] );
388
+			}
736 389
 
737
-        $this->entry = $entry;
738
-    }
390
+			$field->adminOnly = false;
739 391
 
392
+			if( isset( $field->inputs ) && is_array( $field->inputs ) ) {
393
+				foreach( $field->inputs as $key => $input ) {
394
+					$field->inputs[ $key ][ 'id' ] = (string)$input['id'];
395
+				}
396
+			}
397
+		}
740 398
 
741
-    /**
742
-     * Display the Edit Entry form
743
-     *
744
-     * @return [type] [description]
745
-     */
746
-    public function edit_entry_form() {
399
+		return $form;
400
+	}
401
+
402
+	private function update_calculation_fields() {
403
+
404
+		$form = self::$original_form;
405
+		$update = false;
406
+
407
+		// get the most up to date entry values
408
+		$entry = GFAPI::get_entry( $this->entry['id'] );
409
+
410
+		if( !empty( $this->fields_with_calculation ) ) {
411
+			$update = true;
412
+			foreach ( $this->fields_with_calculation as $calc_field ) {
413
+				$inputs = $calc_field->get_entry_inputs();
414
+				if ( is_array( $inputs ) ) {
415
+					foreach ( $inputs as $input ) {
416
+						$input_name = 'input_' . str_replace( '.', '_', $input['id'] );
417
+						$entry[ strval( $input['id'] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry );
418
+					}
419
+				} else {
420
+					$input_name = 'input_' . str_replace( '.', '_', $calc_field->id);
421
+					$entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry );
422
+				}
423
+			}
747 424
 
748
-        ?>
425
+		}
426
+
427
+		//saving total field as the last field of the form.
428
+		if ( ! empty( $this->total_fields ) ) {
429
+			$update = true;
430
+			foreach ( $this->total_fields as $total_field ) {
431
+				$input_name = 'input_' . str_replace( '.', '_', $total_field->id);
432
+				$entry[ strval( $total_field->id ) ] = RGFormsModel::prepare_value( $form, $total_field, '', $input_name, $entry['id'], $entry );
433
+			}
434
+		}
435
+
436
+		if( $update ) {
437
+
438
+			$return_entry = GFAPI::update_entry( $entry );
439
+
440
+			if( is_wp_error( $return_entry ) ) {
441
+				do_action( 'gravityview_log_error', 'Updating the entry calculation and total fields failed', $return_entry );
442
+			} else {
443
+				do_action( 'gravityview_log_debug', 'Updating the entry calculation and total fields succeeded' );
444
+			}
445
+		}
446
+	}
447
+
448
+	/**
449
+	 * Handle updating the Post Image field
450
+	 *
451
+	 * Sets a new Featured Image if configured in Gravity Forms; otherwise uploads/updates media
452
+	 *
453
+	 * @since 1.17
454
+	 *
455
+	 * @uses GFFormsModel::media_handle_upload
456
+	 * @uses set_post_thumbnail
457
+	 * 
458
+	 * @param array $form GF Form array
459
+	 * @param GF_Field $field GF Field
460
+	 * @param string $field_id Numeric ID of the field
461
+	 * @param string $value
462
+	 * @param array $entry GF Entry currently being edited
463
+	 * @param int $post_id ID of the Post being edited
464
+	 *
465
+	 * @return mixed|string
466
+	 */
467
+	private function update_post_image( $form, $field, $field_id, $value, $entry, $post_id ) {
468
+
469
+		$input_name = 'input_' . $field_id;
470
+
471
+		if ( !empty( $_FILES[ $input_name ]['name'] ) ) {
472
+
473
+			// We have a new image
474
+
475
+			$value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'] );
476
+
477
+			$ary = ! empty( $value ) ? explode( '|:|', $value ) : array();
478
+			$img_url = rgar( $ary, 0 );
479
+
480
+			$img_title       = count( $ary ) > 1 ? $ary[1] : '';
481
+			$img_caption     = count( $ary ) > 2 ? $ary[2] : '';
482
+			$img_description = count( $ary ) > 3 ? $ary[3] : '';
483
+
484
+			$image_meta = array(
485
+				'post_excerpt' => $img_caption,
486
+				'post_content' => $img_description,
487
+			);
488
+
489
+			//adding title only if it is not empty. It will default to the file name if it is not in the array
490
+			if ( ! empty( $img_title ) ) {
491
+				$image_meta['post_title'] = $img_title;
492
+			}
493
+
494
+			/**
495
+			 * todo: As soon as \GFFormsModel::media_handle_upload becomes a public method, move this call to \GFFormsModel::media_handle_upload and remove the hack from this class.
496
+			 * Note: the method became public in GF 1.9.17.7, but we don't require that version yet.
497
+			 */
498
+			require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php';
499
+			$media_id = GravityView_GFFormsModel::media_handle_upload( $img_url, $post_id, $image_meta );
500
+
501
+			// is this field set as featured image?
502
+			if ( $media_id && $field->postFeaturedImage ) {
503
+				set_post_thumbnail( $post_id, $media_id );
504
+			}
505
+
506
+		} elseif ( !empty( $_POST[ $input_name ] ) && is_array( $value ) ) {
507
+
508
+			// Same image although the image title, caption or description might have changed
509
+
510
+			$ary = array();
511
+			if( ! empty( $entry[ $field_id ] ) ) {
512
+				$ary = is_array( $entry[ $field_id ] ) ? $entry[ $field_id ] : explode( '|:|', $entry[ $field_id ] );
513
+			}
514
+			$img_url = rgar( $ary, 0 );
515
+
516
+			// is this really the same image or something went wrong ?
517
+			if( $img_url === $_POST[ $input_name ] ) {
518
+
519
+				$img_title       = rgar( $value, $field_id .'.1' );
520
+				$img_caption     = rgar( $value, $field_id .'.4' );
521
+				$img_description = rgar( $value, $field_id .'.7' );
522
+
523
+				$value = ! empty( $img_url ) ? $img_url . "|:|" . $img_title . "|:|" . $img_caption . "|:|" . $img_description : '';
524
+
525
+				if ( $field->postFeaturedImage ) {
526
+
527
+					$image_meta = array(
528
+						'ID' => get_post_thumbnail_id( $post_id ),
529
+						'post_title' => $img_title,
530
+						'post_excerpt' => $img_caption,
531
+						'post_content' => $img_description,
532
+					);
533
+
534
+					// update image title, caption or description
535
+					wp_update_post( $image_meta );
536
+				}
537
+			}
538
+
539
+		} else {
540
+
541
+			// if we get here, image was removed or not set.
542
+			$value = '';
543
+
544
+			if ( $field->postFeaturedImage ) {
545
+				delete_post_thumbnail( $post_id );
546
+			}
547
+		}
548
+
549
+		return $value;
550
+	}
551
+
552
+	/**
553
+	 * Loop through the fields being edited and if they include Post fields, update the Entry's post object
554
+	 *
555
+	 * @param array $form Gravity Forms form
556
+	 *
557
+	 * @return void
558
+	 */
559
+	private function maybe_update_post_fields( $form ) {
560
+
561
+		$post_id = $this->entry['post_id'];
562
+
563
+		// Security check
564
+		if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) {
565
+			do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id );
566
+			return;
567
+		}
568
+
569
+		$update_entry = false;
570
+
571
+		$updated_post = $original_post = get_post( $post_id );
572
+
573
+		foreach ( $this->entry as $field_id => $value ) {
574
+
575
+			$field = RGFormsModel::get_field( $form, $field_id );
576
+
577
+			if( ! $field ) {
578
+				continue;
579
+			}
580
+
581
+			if( GFCommon::is_post_field( $field ) && 'post_category' !== $field->type ) {
582
+
583
+				// Get the value of the field, including $_POSTed value
584
+				$value = RGFormsModel::get_field_value( $field );
585
+
586
+				// Use temporary entry variable, to make values available to fill_post_template() and update_post_image()
587
+				$entry_tmp = $this->entry;
588
+				$entry_tmp["{$field_id}"] = $value;
589
+
590
+				switch( $field->type ) {
591
+
592
+					case 'post_title':
593
+						$post_title = $value;
594
+						if( rgar( $form, 'postTitleTemplateEnabled' ) ) {
595
+							$post_title = $this->fill_post_template( $form['postTitleTemplate'], $form, $entry_tmp );
596
+						}
597
+						$updated_post->post_title = $post_title;
598
+						$updated_post->post_name  = $post_title;
599
+						unset( $post_title );
600
+						break;
601
+
602
+					case 'post_content':
603
+						$post_content = $value;
604
+						if( rgar( $form, 'postContentTemplateEnabled' ) ) {
605
+							$post_content = $this->fill_post_template( $form['postContentTemplate'], $form, $entry_tmp, true );
606
+						}
607
+						$updated_post->post_content = $post_content;
608
+						unset( $post_content );
609
+						break;
610
+					case 'post_excerpt':
611
+						$updated_post->post_excerpt = $value;
612
+						break;
613
+					case 'post_tags':
614
+						wp_set_post_tags( $post_id, $value, false );
615
+						break;
616
+					case 'post_category':
617
+						break;
618
+					case 'post_custom_field':
619
+						if( ! empty( $field->customFieldTemplateEnabled ) ) {
620
+							$value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true );
621
+						}
622
+
623
+						$input_type = RGFormsModel::get_input_type( $field );
624
+
625
+						// Only certain custom field types are supported
626
+						switch( $input_type ) {
627
+							case 'fileupload':
628
+							case 'list':
629
+							case 'multiselect':
630
+								if( ! is_string( $value ) ) {
631
+									$value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value );
632
+								}
633
+							// break; left intentionally out
634
+							default:
635
+								update_post_meta( $post_id, $field->postCustomFieldName, $value );
636
+						}
637
+
638
+						break;
639
+
640
+					case 'post_image':
641
+						$value = $this->update_post_image( $form, $field, $field_id, $value, $this->entry, $post_id );
642
+						break;
643
+
644
+				}
645
+
646
+				// update entry after
647
+				$this->entry["{$field_id}"] = $value;
648
+
649
+				$update_entry = true;
650
+
651
+				unset( $entry_tmp );
652
+			}
653
+
654
+		}
655
+
656
+		if( $update_entry ) {
657
+
658
+			$return_entry = GFAPI::update_entry( $this->entry );
659
+
660
+			if( is_wp_error( $return_entry ) ) {
661
+			   do_action( 'gravityview_log_error', 'Updating the entry post fields failed', array( '$this->entry' => $this->entry, '$return_entry' => $return_entry ) );
662
+			} else {
663
+				do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' );
664
+			}
665
+
666
+		}
667
+
668
+		$return_post = wp_update_post( $updated_post, true );
669
+
670
+		if( is_wp_error( $return_post ) ) {
671
+			$return_post->add_data( $updated_post, '$updated_post' );
672
+			do_action( 'gravityview_log_error', 'Updating the post content failed', compact( 'updated_post', 'return_post' ) );
673
+		} else {
674
+			do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post );
675
+		}
676
+	}
677
+
678
+	/**
679
+	 * Convert a field content template into prepared output
680
+	 *
681
+	 * @uses GravityView_GFFormsModel::get_post_field_images()
682
+	 *
683
+	 * @since 1.17
684
+	 *
685
+	 * @param string $template The content template for the field
686
+	 * @param array $form Gravity Forms form
687
+	 * @param bool $do_shortcode Whether to process shortcode inside content. In GF, only run on Custom Field and Post Content fields
688
+	 *
689
+	 * @return mixed|string|void
690
+	 */
691
+	function fill_post_template( $template, $form, $entry, $do_shortcode = false ) {
692
+
693
+		require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php';
694
+
695
+		$post_images = GravityView_GFFormsModel::get_post_field_images( $form, $entry );
696
+
697
+		//replacing post image variables
698
+		$output = GFCommon::replace_variables_post_image( $template, $post_images, $entry );
699
+
700
+		//replacing all other variables
701
+		$output = GFCommon::replace_variables( $output, $form, $entry, false, false, false );
702
+
703
+		// replace conditional shortcodes
704
+		if( $do_shortcode ) {
705
+			$output = do_shortcode( $output );
706
+		}
707
+
708
+		return $output;
709
+	}
710
+
711
+
712
+	/**
713
+	 * Perform actions normally performed after updating a lead
714
+	 *
715
+	 * @since 1.8
716
+	 *
717
+	 * @see GFEntryDetail::lead_detail_page()
718
+	 *
719
+	 * @return void
720
+	 */
721
+	function after_update() {
722
+
723
+		do_action( 'gform_after_update_entry', $this->form, $this->entry['id'], self::$original_entry );
724
+		do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] );
725
+
726
+		// Re-define the entry now that we've updated it.
727
+		$entry = RGFormsModel::get_lead( $this->entry['id'] );
728
+
729
+		$entry = GFFormsModel::set_entry_meta( $entry, $this->form );
730
+
731
+		// We need to clear the cache because Gravity Forms caches the field values, which
732
+		// we have just updated.
733
+		foreach ($this->form['fields'] as $key => $field) {
734
+			GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id );
735
+		}
736
+
737
+		$this->entry = $entry;
738
+	}
739
+
740
+
741
+	/**
742
+	 * Display the Edit Entry form
743
+	 *
744
+	 * @return [type] [description]
745
+	 */
746
+	public function edit_entry_form() {
747
+
748
+		?>
749 749
 
750 750
         <div class="gv-edit-entry-wrapper"><?php
751 751
 
752
-            $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this );
752
+			$javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this );
753 753
 
754
-            /**
755
-             * Fixes weird wpautop() issue
756
-             * @see https://github.com/katzwebservices/GravityView/issues/451
757
-             */
758
-            echo gravityview_strip_whitespace( $javascript );
754
+			/**
755
+			 * Fixes weird wpautop() issue
756
+			 * @see https://github.com/katzwebservices/GravityView/issues/451
757
+			 */
758
+			echo gravityview_strip_whitespace( $javascript );
759 759
 
760
-            ?><h2 class="gv-edit-entry-title">
760
+			?><h2 class="gv-edit-entry-title">
761 761
                 <span><?php
762 762
 
763
-                    /**
764
-                     * @filter `gravityview_edit_entry_title` Modify the edit entry title
765
-                     * @param string $edit_entry_title Modify the "Edit Entry" title
766
-                     * @param GravityView_Edit_Entry_Render $this This object
767
-                     */
768
-                    $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this );
763
+					/**
764
+					 * @filter `gravityview_edit_entry_title` Modify the edit entry title
765
+					 * @param string $edit_entry_title Modify the "Edit Entry" title
766
+					 * @param GravityView_Edit_Entry_Render $this This object
767
+					 */
768
+					$edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this );
769 769
 
770
-                    echo esc_attr( $edit_entry_title );
771
-            ?></span>
770
+					echo esc_attr( $edit_entry_title );
771
+			?></span>
772 772
             </h2>
773 773
 
774 774
             <?php $this->maybe_print_message(); ?>
@@ -779,1144 +779,1144 @@  discard block
 block discarded – undo
779 779
 
780 780
                 <?php
781 781
 
782
-                wp_nonce_field( self::$nonce_key, self::$nonce_key );
782
+				wp_nonce_field( self::$nonce_key, self::$nonce_key );
783 783
 
784
-                wp_nonce_field( self::$nonce_field, self::$nonce_field, false );
784
+				wp_nonce_field( self::$nonce_field, self::$nonce_field, false );
785 785
 
786
-                // Print the actual form HTML
787
-                $this->render_edit_form();
786
+				// Print the actual form HTML
787
+				$this->render_edit_form();
788 788
 
789
-                ?>
789
+				?>
790 790
             </form>
791 791
 
792 792
         </div>
793 793
 
794 794
     <?php
795
-    }
796
-
797
-    /**
798
-     * Display success or error message if the form has been submitted
799
-     *
800
-     * @uses GVCommon::generate_notice
801
-     *
802
-     * @since 1.16.2.2
803
-     *
804
-     * @return void
805
-     */
806
-    private function maybe_print_message() {
807
-
808
-        if( rgpost('action') === 'update' ) {
809
-
810
-            $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) );
811
-
812
-            if( ! $this->is_valid ){
813
-
814
-                // Keeping this compatible with Gravity Forms.
815
-                $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>";
816
-                $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form);
817
-
818
-                echo GVCommon::generate_notice( $message , 'gv-error' );
819
-
820
-            } else {
821
-                $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' );
822
-
823
-                /**
824
-                 * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link)
825
-                 * @since 1.5.4
826
-                 * @param string $entry_updated_message Existing message
827
-                 * @param int $view_id View ID
828
-                 * @param array $entry Gravity Forms entry array
829
-                 * @param string $back_link URL to return to the original entry. @since 1.6
830
-                 */
831
-                $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link );
832
-
833
-                echo GVCommon::generate_notice( $message );
834
-            }
835
-
836
-        }
837
-    }
838
-
839
-    /**
840
-     * Display the Edit Entry form in the original Gravity Forms format
841
-     *
842
-     * @since 1.9
843
-     *
844
-     * @return void
845
-     */
846
-    private function render_edit_form() {
847
-
848
-        /**
849
-         * @action `gravityview/edit-entry/render/before` Before rendering the Edit Entry form
850
-         * @since 1.17
851
-         * @param GravityView_Edit_Entry_Render $this
852
-         */
853
-        do_action( 'gravityview/edit-entry/render/before', $this );
854
-
855
-        add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 );
856
-        add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') );
857
-        add_filter( 'gform_disable_view_counter', '__return_true' );
858
-
859
-        add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 );
860
-        add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 );
861
-
862
-        add_filter( 'gform_field_value', array( $this, 'fix_survey_fields_value'), 10, 3 );
863
-
864
-        // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin.
865
-        unset( $_GET['page'] );
866
-
867
-        // TODO: Verify multiple-page forms
868
-        // TODO: Product fields are not editable
869
-
870
-        $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry );
871
-
872
-        remove_filter( 'gform_field_value', array( $this, 'fix_survey_fields_value'), 10 );
873
-	    remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 );
874
-        remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) );
875
-        remove_filter( 'gform_disable_view_counter', '__return_true' );
876
-        remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 );
877
-        remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 );
878
-
879
-        echo $html;
880
-
881
-        /**
882
-         * @action `gravityview/edit-entry/render/after` After rendering the Edit Entry form
883
-         * @since 1.17
884
-         * @param GravityView_Edit_Entry_Render $this
885
-         */
886
-        do_action( 'gravityview/edit-entry/render/after', $this );
887
-    }
888
-
889
-    /**
890
-     * Survey fields inject their output using `gform_field_input` filter, but in Edit Entry, the values were empty.
891
-     * We filter the values here because it was the easiest access point: tell the survey field the correct value, GF outputs it.
892
-     *
893
-     * @TODO: REMOVE; now added in class-gravityview-plugin-hooks-gravity-forms-survey.php
894
-     * 
895
-     * @since 1.16.4
896
-     *
897
-     * @param string $value Existing value
898
-     * @param GF_Field $field
899
-     * @param string $name Field custom parameter name, normally blank.
900
-     *
901
-     * @return mixed
902
-     */
903
-    function fix_survey_fields_value( $value, $field, $name ) {
795
+	}
796
+
797
+	/**
798
+	 * Display success or error message if the form has been submitted
799
+	 *
800
+	 * @uses GVCommon::generate_notice
801
+	 *
802
+	 * @since 1.16.2.2
803
+	 *
804
+	 * @return void
805
+	 */
806
+	private function maybe_print_message() {
807
+
808
+		if( rgpost('action') === 'update' ) {
809
+
810
+			$back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) );
811
+
812
+			if( ! $this->is_valid ){
813
+
814
+				// Keeping this compatible with Gravity Forms.
815
+				$validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>";
816
+				$message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form);
817
+
818
+				echo GVCommon::generate_notice( $message , 'gv-error' );
819
+
820
+			} else {
821
+				$entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' );
822
+
823
+				/**
824
+				 * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link)
825
+				 * @since 1.5.4
826
+				 * @param string $entry_updated_message Existing message
827
+				 * @param int $view_id View ID
828
+				 * @param array $entry Gravity Forms entry array
829
+				 * @param string $back_link URL to return to the original entry. @since 1.6
830
+				 */
831
+				$message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link );
832
+
833
+				echo GVCommon::generate_notice( $message );
834
+			}
835
+
836
+		}
837
+	}
838
+
839
+	/**
840
+	 * Display the Edit Entry form in the original Gravity Forms format
841
+	 *
842
+	 * @since 1.9
843
+	 *
844
+	 * @return void
845
+	 */
846
+	private function render_edit_form() {
847
+
848
+		/**
849
+		 * @action `gravityview/edit-entry/render/before` Before rendering the Edit Entry form
850
+		 * @since 1.17
851
+		 * @param GravityView_Edit_Entry_Render $this
852
+		 */
853
+		do_action( 'gravityview/edit-entry/render/before', $this );
854
+
855
+		add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 );
856
+		add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') );
857
+		add_filter( 'gform_disable_view_counter', '__return_true' );
858
+
859
+		add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 );
860
+		add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 );
861
+
862
+		add_filter( 'gform_field_value', array( $this, 'fix_survey_fields_value'), 10, 3 );
863
+
864
+		// We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin.
865
+		unset( $_GET['page'] );
866
+
867
+		// TODO: Verify multiple-page forms
868
+		// TODO: Product fields are not editable
869
+
870
+		$html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry );
871
+
872
+		remove_filter( 'gform_field_value', array( $this, 'fix_survey_fields_value'), 10 );
873
+		remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 );
874
+		remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) );
875
+		remove_filter( 'gform_disable_view_counter', '__return_true' );
876
+		remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 );
877
+		remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 );
878
+
879
+		echo $html;
880
+
881
+		/**
882
+		 * @action `gravityview/edit-entry/render/after` After rendering the Edit Entry form
883
+		 * @since 1.17
884
+		 * @param GravityView_Edit_Entry_Render $this
885
+		 */
886
+		do_action( 'gravityview/edit-entry/render/after', $this );
887
+	}
888
+
889
+	/**
890
+	 * Survey fields inject their output using `gform_field_input` filter, but in Edit Entry, the values were empty.
891
+	 * We filter the values here because it was the easiest access point: tell the survey field the correct value, GF outputs it.
892
+	 *
893
+	 * @TODO: REMOVE; now added in class-gravityview-plugin-hooks-gravity-forms-survey.php
894
+	 * 
895
+	 * @since 1.16.4
896
+	 *
897
+	 * @param string $value Existing value
898
+	 * @param GF_Field $field
899
+	 * @param string $name Field custom parameter name, normally blank.
900
+	 *
901
+	 * @return mixed
902
+	 */
903
+	function fix_survey_fields_value( $value, $field, $name ) {
904 904
         
905
-        if( 'survey' === $field->type ) {
906
-
907
-	        // We need to run through each survey row until we find a match for expected values
908
-	        foreach ( $this->entry as $field_id => $field_value ) {
909
-
910
-		        if ( floor( $field_id ) !== floor( $field->id ) ) {
911
-			        continue;
912
-		        }
913
-
914
-		        if( rgar( $field, 'gsurveyLikertEnableMultipleRows' ) ) {
915
-			        list( $row_val, $col_val ) = explode( ':', $field_value, 2 );
916
-
917
-		            // If the $name matches the $row_val, we are processing the correct row
918
-			        if( $row_val === $name ) {
919
-				        $value = $field_value;
920
-				        break;
921
-			        }
922
-		        } else {
923
-			        // When not processing multiple rows, the value is the $entry[ $field_id ] value.
924
-			        $value = $field_value;
925
-				    break;
926
-		        }
905
+		if( 'survey' === $field->type ) {
906
+
907
+			// We need to run through each survey row until we find a match for expected values
908
+			foreach ( $this->entry as $field_id => $field_value ) {
909
+
910
+				if ( floor( $field_id ) !== floor( $field->id ) ) {
911
+					continue;
912
+				}
913
+
914
+				if( rgar( $field, 'gsurveyLikertEnableMultipleRows' ) ) {
915
+					list( $row_val, $col_val ) = explode( ':', $field_value, 2 );
916
+
917
+					// If the $name matches the $row_val, we are processing the correct row
918
+					if( $row_val === $name ) {
919
+						$value = $field_value;
920
+						break;
921
+					}
922
+				} else {
923
+					// When not processing multiple rows, the value is the $entry[ $field_id ] value.
924
+					$value = $field_value;
925
+					break;
926
+				}
927 927
 			}
928
-        }
929
-
930
-        return $value;
931
-    }
932
-
933
-    /**
934
-     * Display the Update/Cancel/Delete buttons for the Edit Entry form
935
-     * @since 1.8
936
-     * @return string
937
-     */
938
-    public function render_form_buttons() {
939
-        return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this );
940
-    }
941
-
942
-
943
-    /**
944
-     * Modify the form fields that are shown when using GFFormDisplay::get_form()
945
-     *
946
-     * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown.
947
-     *
948
-     * @param array $form
949
-     * @param boolean $ajax Whether in AJAX mode
950
-     * @param array|string $field_values Passed parameters to the form
951
-     *
952
-     * @since 1.9
953
-     *
954
-     * @return array Modified form array
955
-     */
956
-    public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) {
957
-
958
-        // In case we have validated the form, use it to inject the validation results into the form render
959
-        if( isset( $this->form_after_validation ) ) {
960
-            $form = $this->form_after_validation;
961
-        } else {
962
-            $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id );
963
-        }
964
-
965
-        $form = $this->filter_conditional_logic( $form );
966
-
967
-        // for now we don't support Save and Continue feature.
968
-        if( ! self::$supports_save_and_continue ) {
969
-	        unset( $form['save'] );
970
-        }
971
-
972
-        return $form;
973
-    }
974
-
975
-    /**
976
-     * 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.
977
-     *
978
-     * @since 1.16.2.2
979
-     *
980
-     * @param string $field_content Always empty. Returning not-empty overrides the input.
981
-     * @param GF_Field $field
982
-     * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
983
-     * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
984
-     * @param int $form_id Form ID
985
-     *
986
-     * @return string If error, the error message. If no error, blank string (modify_edit_field_input() runs next)
987
-     */
988
-    function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) {
989
-
990
-        if( GFCommon::is_post_field( $field ) ) {
991
-
992
-            $message = null;
993
-
994
-            // First, make sure they have the capability to edit the post.
995
-            if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) {
996
-
997
-                /**
998
-                 * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post
999
-                 * @param string $message The existing "You don't have permission..." text
1000
-                 */
1001
-                $message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don&rsquo;t have permission to edit this post.', 'gravityview') );
1002
-
1003
-            } elseif( null === get_post( $this->entry['post_id'] ) ) {
1004
-                /**
1005
-                 * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists
1006
-                 * @param string $message The existing "This field is not editable; the post no longer exists." text
1007
-                 */
1008
-                $message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) );
1009
-            }
1010
-
1011
-            if( $message ) {
1012
-                $field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) );
1013
-            }
1014
-        }
1015
-
1016
-        return $field_content;
1017
-    }
1018
-
1019
-    /**
1020
-     *
1021
-     * Fill-in the saved values into the form inputs
1022
-     *
1023
-     * @param string $field_content Always empty. Returning not-empty overrides the input.
1024
-     * @param GF_Field $field
1025
-     * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
1026
-     * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
1027
-     * @param int $form_id Form ID
1028
-     *
1029
-     * @return mixed
1030
-     */
1031
-    function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) {
1032
-
1033
-        $gv_field = GravityView_Fields::get_associated_field( $field );
1034
-
1035
-        // If the form has been submitted, then we don't need to pre-fill the values,
1036
-        // Except for fileupload type and when a field input is overridden- run always!!
1037
-        if(
1038
-            ( $this->is_edit_entry_submission() && !in_array( $field->type, array( 'fileupload', 'post_image' ) ) )
1039
-            && false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) )
1040
-            || ! empty( $field_content )
1041
-            || in_array( $field->type, array( 'honeypot' ) )
1042
-            || GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable
1043
-        ) {
1044
-	        return $field_content;
1045
-        }
1046
-
1047
-        // Turn on Admin-style display for file upload fields only
1048
-        if( 'fileupload' === $field->type ) {
1049
-            $_GET['page'] = 'gf_entries';
1050
-        }
1051
-
1052
-        // SET SOME FIELD DEFAULTS TO PREVENT ISSUES
1053
-        $field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */
1054
-
1055
-        // add categories as choices for Post Category field
1056
-        if ( 'post_category' === $field->type ) {
1057
-            $field = GFCommon::add_categories_as_choices( $field, $value );
1058
-        }
1059
-
1060
-        $field_value = $this->get_field_value( $field );
1061
-
1062
-        /**
1063
-         * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed
1064
-         * @since 1.11
1065
-         * @param mixed $field_value field value used to populate the input
1066
-         * @param object $field Gravity Forms field object ( Class GF_Field )
1067
-         */
1068
-        $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field );
1069
-
1070
-        /**
1071
-         * @filter `gravityview/edit_entry/field_value_{field_type}` Change the value of an Edit Entry field for a specific field type
1072
-         * @since 1.17
1073
-         * @param mixed $field_value field value used to populate the input
1074
-         * @param GF_Field $field Gravity Forms field object
1075
-         */
1076
-        $field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type , $field_value, $field );
1077
-
1078
-	    // Prevent any PHP warnings, like undefined index
1079
-	    ob_start();
1080
-
1081
-        if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) {
1082
-            /** @var GF_Field $gv_field */
1083
-            $return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field );
1084
-        } else {
1085
-	        $return = $field->get_field_input( $this->form, $field_value, $this->entry );
1086
-        }
1087
-
1088
-
1089
-	    // If there was output, it's an error
1090
-	    $warnings = ob_get_clean();
1091
-
1092
-	    if( !empty( $warnings ) ) {
1093
-		    do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value );
1094
-	    }
1095
-
1096
-        /**
1097
-         * Unset hack $_GET['page'] = 'gf_entries'
1098
-         * We need the fileupload html field to render with the proper id
1099
-         *  ( <li id="field_80_16" ... > )
1100
-         */
1101
-        unset( $_GET['page'] );
1102
-
1103
-        return $return;
1104
-    }
1105
-
1106
-    /**
1107
-     * Modify the value for the current field input
1108
-     *
1109
-     * @param GF_Field $field
1110
-     *
1111
-     * @return array|mixed|string|void
1112
-     */
1113
-    private function get_field_value( $field ) {
1114
-
1115
-        /**
1116
-         * @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.
1117
-         * @param boolean True: override saved values; False: don't override (default)
1118
-         * @param $field GF_Field object Gravity Forms field object
1119
-         * @since 1.13
1120
-         */
1121
-        $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field );
1122
-
1123
-        // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs)
1124
-        if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) {
1125
-
1126
-            $field_value = array();
1127
-
1128
-            // only accept pre-populated values if the field doesn't have any choice selected.
1129
-            $allow_pre_populated = $field->allowsPrepopulate;
1130
-
1131
-            foreach ( (array)$field->inputs as $input ) {
1132
-
1133
-                $input_id = strval( $input['id'] );
928
+		}
929
+
930
+		return $value;
931
+	}
932
+
933
+	/**
934
+	 * Display the Update/Cancel/Delete buttons for the Edit Entry form
935
+	 * @since 1.8
936
+	 * @return string
937
+	 */
938
+	public function render_form_buttons() {
939
+		return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this );
940
+	}
941
+
942
+
943
+	/**
944
+	 * Modify the form fields that are shown when using GFFormDisplay::get_form()
945
+	 *
946
+	 * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown.
947
+	 *
948
+	 * @param array $form
949
+	 * @param boolean $ajax Whether in AJAX mode
950
+	 * @param array|string $field_values Passed parameters to the form
951
+	 *
952
+	 * @since 1.9
953
+	 *
954
+	 * @return array Modified form array
955
+	 */
956
+	public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) {
957
+
958
+		// In case we have validated the form, use it to inject the validation results into the form render
959
+		if( isset( $this->form_after_validation ) ) {
960
+			$form = $this->form_after_validation;
961
+		} else {
962
+			$form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id );
963
+		}
964
+
965
+		$form = $this->filter_conditional_logic( $form );
966
+
967
+		// for now we don't support Save and Continue feature.
968
+		if( ! self::$supports_save_and_continue ) {
969
+			unset( $form['save'] );
970
+		}
971
+
972
+		return $form;
973
+	}
974
+
975
+	/**
976
+	 * 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.
977
+	 *
978
+	 * @since 1.16.2.2
979
+	 *
980
+	 * @param string $field_content Always empty. Returning not-empty overrides the input.
981
+	 * @param GF_Field $field
982
+	 * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
983
+	 * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
984
+	 * @param int $form_id Form ID
985
+	 *
986
+	 * @return string If error, the error message. If no error, blank string (modify_edit_field_input() runs next)
987
+	 */
988
+	function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) {
989
+
990
+		if( GFCommon::is_post_field( $field ) ) {
991
+
992
+			$message = null;
993
+
994
+			// First, make sure they have the capability to edit the post.
995
+			if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) {
996
+
997
+				/**
998
+				 * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post
999
+				 * @param string $message The existing "You don't have permission..." text
1000
+				 */
1001
+				$message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don&rsquo;t have permission to edit this post.', 'gravityview') );
1002
+
1003
+			} elseif( null === get_post( $this->entry['post_id'] ) ) {
1004
+				/**
1005
+				 * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists
1006
+				 * @param string $message The existing "This field is not editable; the post no longer exists." text
1007
+				 */
1008
+				$message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) );
1009
+			}
1010
+
1011
+			if( $message ) {
1012
+				$field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) );
1013
+			}
1014
+		}
1015
+
1016
+		return $field_content;
1017
+	}
1018
+
1019
+	/**
1020
+	 *
1021
+	 * Fill-in the saved values into the form inputs
1022
+	 *
1023
+	 * @param string $field_content Always empty. Returning not-empty overrides the input.
1024
+	 * @param GF_Field $field
1025
+	 * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
1026
+	 * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
1027
+	 * @param int $form_id Form ID
1028
+	 *
1029
+	 * @return mixed
1030
+	 */
1031
+	function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) {
1032
+
1033
+		$gv_field = GravityView_Fields::get_associated_field( $field );
1034
+
1035
+		// If the form has been submitted, then we don't need to pre-fill the values,
1036
+		// Except for fileupload type and when a field input is overridden- run always!!
1037
+		if(
1038
+			( $this->is_edit_entry_submission() && !in_array( $field->type, array( 'fileupload', 'post_image' ) ) )
1039
+			&& false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) )
1040
+			|| ! empty( $field_content )
1041
+			|| in_array( $field->type, array( 'honeypot' ) )
1042
+			|| GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable
1043
+		) {
1044
+			return $field_content;
1045
+		}
1046
+
1047
+		// Turn on Admin-style display for file upload fields only
1048
+		if( 'fileupload' === $field->type ) {
1049
+			$_GET['page'] = 'gf_entries';
1050
+		}
1051
+
1052
+		// SET SOME FIELD DEFAULTS TO PREVENT ISSUES
1053
+		$field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */
1054
+
1055
+		// add categories as choices for Post Category field
1056
+		if ( 'post_category' === $field->type ) {
1057
+			$field = GFCommon::add_categories_as_choices( $field, $value );
1058
+		}
1059
+
1060
+		$field_value = $this->get_field_value( $field );
1061
+
1062
+		/**
1063
+		 * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed
1064
+		 * @since 1.11
1065
+		 * @param mixed $field_value field value used to populate the input
1066
+		 * @param object $field Gravity Forms field object ( Class GF_Field )
1067
+		 */
1068
+		$field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field );
1069
+
1070
+		/**
1071
+		 * @filter `gravityview/edit_entry/field_value_{field_type}` Change the value of an Edit Entry field for a specific field type
1072
+		 * @since 1.17
1073
+		 * @param mixed $field_value field value used to populate the input
1074
+		 * @param GF_Field $field Gravity Forms field object
1075
+		 */
1076
+		$field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type , $field_value, $field );
1077
+
1078
+		// Prevent any PHP warnings, like undefined index
1079
+		ob_start();
1080
+
1081
+		if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) {
1082
+			/** @var GF_Field $gv_field */
1083
+			$return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field );
1084
+		} else {
1085
+			$return = $field->get_field_input( $this->form, $field_value, $this->entry );
1086
+		}
1087
+
1088
+
1089
+		// If there was output, it's an error
1090
+		$warnings = ob_get_clean();
1091
+
1092
+		if( !empty( $warnings ) ) {
1093
+			do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value );
1094
+		}
1095
+
1096
+		/**
1097
+		 * Unset hack $_GET['page'] = 'gf_entries'
1098
+		 * We need the fileupload html field to render with the proper id
1099
+		 *  ( <li id="field_80_16" ... > )
1100
+		 */
1101
+		unset( $_GET['page'] );
1102
+
1103
+		return $return;
1104
+	}
1105
+
1106
+	/**
1107
+	 * Modify the value for the current field input
1108
+	 *
1109
+	 * @param GF_Field $field
1110
+	 *
1111
+	 * @return array|mixed|string|void
1112
+	 */
1113
+	private function get_field_value( $field ) {
1114
+
1115
+		/**
1116
+		 * @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.
1117
+		 * @param boolean True: override saved values; False: don't override (default)
1118
+		 * @param $field GF_Field object Gravity Forms field object
1119
+		 * @since 1.13
1120
+		 */
1121
+		$override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field );
1122
+
1123
+		// We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs)
1124
+		if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) {
1125
+
1126
+			$field_value = array();
1127
+
1128
+			// only accept pre-populated values if the field doesn't have any choice selected.
1129
+			$allow_pre_populated = $field->allowsPrepopulate;
1130
+
1131
+			foreach ( (array)$field->inputs as $input ) {
1132
+
1133
+				$input_id = strval( $input['id'] );
1134 1134
                 
1135
-                if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) {
1136
-                    $field_value[ $input_id ] =  'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ];
1137
-                    $allow_pre_populated = false;
1138
-                }
1135
+				if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) {
1136
+					$field_value[ $input_id ] =  'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ];
1137
+					$allow_pre_populated = false;
1138
+				}
1139 1139
 
1140
-            }
1140
+			}
1141 1141
 
1142
-            $pre_value = $field->get_value_submission( array(), false );
1142
+			$pre_value = $field->get_value_submission( array(), false );
1143 1143
 
1144
-            $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value;
1144
+			$field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value;
1145 1145
 
1146
-        } else {
1146
+		} else {
1147 1147
 
1148
-            $id = intval( $field->id );
1148
+			$id = intval( $field->id );
1149 1149
 
1150
-            // get pre-populated value if exists
1151
-            $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : '';
1150
+			// get pre-populated value if exists
1151
+			$pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : '';
1152 1152
 
1153
-            // saved field entry value (if empty, fallback to the pre-populated value, if exists)
1154
-            // or pre-populated value if not empty and set to override saved value
1155
-            $field_value = !gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value;
1153
+			// saved field entry value (if empty, fallback to the pre-populated value, if exists)
1154
+			// or pre-populated value if not empty and set to override saved value
1155
+			$field_value = !gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value;
1156 1156
 
1157
-            // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs.
1158
-            if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) {
1159
-                $categories = array();
1160
-                foreach ( explode( ',', $field_value ) as $cat_string ) {
1161
-                    $categories[] = GFCommon::format_post_category( $cat_string, true );
1162
-                }
1163
-                $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories );
1164
-            }
1157
+			// in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs.
1158
+			if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) {
1159
+				$categories = array();
1160
+				foreach ( explode( ',', $field_value ) as $cat_string ) {
1161
+					$categories[] = GFCommon::format_post_category( $cat_string, true );
1162
+				}
1163
+				$field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories );
1164
+			}
1165 1165
 
1166
-        }
1166
+		}
1167 1167
 
1168
-        // if value is empty get the default value if defined
1169
-        $field_value = $field->get_value_default_if_empty( $field_value );
1168
+		// if value is empty get the default value if defined
1169
+		$field_value = $field->get_value_default_if_empty( $field_value );
1170 1170
 
1171
-        return $field_value;
1172
-    }
1171
+		return $field_value;
1172
+	}
1173 1173
 
1174 1174
 
1175
-    // ---- Entry validation
1175
+	// ---- Entry validation
1176 1176
 
1177
-    /**
1178
-     * Add field keys that Gravity Forms expects.
1179
-     *
1180
-     * @see GFFormDisplay::validate()
1181
-     * @param  array $form GF Form
1182
-     * @return array       Modified GF Form
1183
-     */
1184
-    function gform_pre_validation( $form ) {
1177
+	/**
1178
+	 * Add field keys that Gravity Forms expects.
1179
+	 *
1180
+	 * @see GFFormDisplay::validate()
1181
+	 * @param  array $form GF Form
1182
+	 * @return array       Modified GF Form
1183
+	 */
1184
+	function gform_pre_validation( $form ) {
1185 1185
 
1186
-        if( ! $this->verify_nonce() ) {
1187
-            return $form;
1188
-        }
1186
+		if( ! $this->verify_nonce() ) {
1187
+			return $form;
1188
+		}
1189 1189
 
1190
-        // Fix PHP warning regarding undefined index.
1191
-        foreach ( $form['fields'] as &$field) {
1190
+		// Fix PHP warning regarding undefined index.
1191
+		foreach ( $form['fields'] as &$field) {
1192 1192
 
1193
-            // This is because we're doing admin form pretending to be front-end, so Gravity Forms
1194
-            // expects certain field array items to be set.
1195
-            foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) {
1196
-	            $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL;
1197
-            }
1193
+			// This is because we're doing admin form pretending to be front-end, so Gravity Forms
1194
+			// expects certain field array items to be set.
1195
+			foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) {
1196
+				$field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL;
1197
+			}
1198 1198
 
1199
-            // unset emailConfirmEnabled for email type fields
1200
-           /* if( 'email' === $field['type'] && !empty( $field['emailConfirmEnabled'] ) ) {
1199
+			// unset emailConfirmEnabled for email type fields
1200
+		   /* if( 'email' === $field['type'] && !empty( $field['emailConfirmEnabled'] ) ) {
1201 1201
                 $field['emailConfirmEnabled'] = '';
1202 1202
             }*/
1203 1203
 
1204
-            switch( RGFormsModel::get_input_type( $field ) ) {
1204
+			switch( RGFormsModel::get_input_type( $field ) ) {
1205
+
1206
+				/**
1207
+				 * 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.
1208
+				 *
1209
+				 * 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.
1210
+				 *
1211
+				 * @hack
1212
+				 */
1213
+				case 'fileupload':
1214
+
1215
+					// Set the previous value
1216
+					$entry = $this->get_entry();
1217
+
1218
+					$input_name = 'input_'.$field->id;
1219
+					$form_id = $form['id'];
1220
+
1221
+					$value = NULL;
1205 1222
 
1206
-                /**
1207
-                 * 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.
1208
-                 *
1209
-                 * 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.
1210
-                 *
1211
-                 * @hack
1212
-                 */
1213
-                case 'fileupload':
1214
-
1215
-                    // Set the previous value
1216
-                    $entry = $this->get_entry();
1217
-
1218
-                    $input_name = 'input_'.$field->id;
1219
-                    $form_id = $form['id'];
1220
-
1221
-                    $value = NULL;
1222
-
1223
-                    // Use the previous entry value as the default.
1224
-                    if( isset( $entry[ $field->id ] ) ) {
1225
-                        $value = $entry[ $field->id ];
1226
-                    }
1223
+					// Use the previous entry value as the default.
1224
+					if( isset( $entry[ $field->id ] ) ) {
1225
+						$value = $entry[ $field->id ];
1226
+					}
1227 1227
 
1228
-                    // If this is a single upload file
1229
-                    if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) {
1230
-                        $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] );
1231
-                        $value = $file_path['url'];
1228
+					// If this is a single upload file
1229
+					if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) {
1230
+						$file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] );
1231
+						$value = $file_path['url'];
1232 1232
 
1233
-                    } else {
1234
-
1235
-                        // Fix PHP warning on line 1498 of form_display.php for post_image fields
1236
-                        // Fix PHP Notice:  Undefined index:  size in form_display.php on line 1511
1237
-                        $_FILES[ $input_name ] = array('name' => '', 'size' => '' );
1238
-
1239
-                    }
1240
-
1241
-                    if( rgar($field, "multipleFiles") ) {
1242
-
1243
-                        // If there are fresh uploads, process and merge them.
1244
-                        // Otherwise, use the passed values, which should be json-encoded array of URLs
1245
-                        if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) {
1246
-                            $value = empty( $value ) ? '[]' : $value;
1247
-                            $value = stripslashes_deep( $value );
1248
-                            $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array());
1249
-                        }
1233
+					} else {
1250 1234
 
1251
-                    } else {
1235
+						// Fix PHP warning on line 1498 of form_display.php for post_image fields
1236
+						// Fix PHP Notice:  Undefined index:  size in form_display.php on line 1511
1237
+						$_FILES[ $input_name ] = array('name' => '', 'size' => '' );
1252 1238
 
1253
-                        // A file already exists when editing an entry
1254
-                        // We set this to solve issue when file upload fields are required.
1255
-                        GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value;
1239
+					}
1256 1240
 
1257
-                    }
1241
+					if( rgar($field, "multipleFiles") ) {
1258 1242
 
1259
-                    $this->entry[ $input_name ] = $value;
1260
-                    $_POST[ $input_name ] = $value;
1243
+						// If there are fresh uploads, process and merge them.
1244
+						// Otherwise, use the passed values, which should be json-encoded array of URLs
1245
+						if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) {
1246
+							$value = empty( $value ) ? '[]' : $value;
1247
+							$value = stripslashes_deep( $value );
1248
+							$value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array());
1249
+						}
1261 1250
 
1262
-                    break;
1251
+					} else {
1263 1252
 
1264
-                case 'number':
1265
-                    // Fix "undefined index" issue at line 1286 in form_display.php
1266
-                    if( !isset( $_POST['input_'.$field->id ] ) ) {
1267
-                        $_POST['input_'.$field->id ] = NULL;
1268
-                    }
1269
-                    break;
1270
-                case 'captcha':
1271
-                    // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php
1272
-                    $_POST['recaptcha_challenge_field'] = NULL;
1273
-                    $_POST['recaptcha_response_field'] = NULL;
1274
-                    break;
1275
-            }
1253
+						// A file already exists when editing an entry
1254
+						// We set this to solve issue when file upload fields are required.
1255
+						GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value;
1276 1256
 
1277
-        }
1257
+					}
1278 1258
 
1279
-        return $form;
1280
-    }
1259
+					$this->entry[ $input_name ] = $value;
1260
+					$_POST[ $input_name ] = $value;
1281 1261
 
1262
+					break;
1282 1263
 
1283
-    /**
1284
-     * Process validation for a edit entry submission
1285
-     *
1286
-     * Sets the `is_valid` object var
1287
-     *
1288
-     * @return void
1289
-     */
1290
-    function validate() {
1264
+				case 'number':
1265
+					// Fix "undefined index" issue at line 1286 in form_display.php
1266
+					if( !isset( $_POST['input_'.$field->id ] ) ) {
1267
+						$_POST['input_'.$field->id ] = NULL;
1268
+					}
1269
+					break;
1270
+				case 'captcha':
1271
+					// Fix issue with recaptcha_check_answer() on line 1458 in form_display.php
1272
+					$_POST['recaptcha_challenge_field'] = NULL;
1273
+					$_POST['recaptcha_response_field'] = NULL;
1274
+					break;
1275
+			}
1276
+
1277
+		}
1278
+
1279
+		return $form;
1280
+	}
1291 1281
 
1292
-        /**
1293
-         * If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry
1294
-         * GF User Registration Add-on version > 3.x has a different class name
1295
-         * @since 1.16.2
1296
-         */
1297
-        if ( class_exists( 'GF_User_Registration' ) ) {
1298
-            remove_filter( 'gform_validation', array( GF_User_Registration::get_instance(), 'validate' ) );
1299
-        } else  if ( class_exists( 'GFUser' ) ) {
1300
-            remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) );
1301
-        }
1302 1282
 
1283
+	/**
1284
+	 * Process validation for a edit entry submission
1285
+	 *
1286
+	 * Sets the `is_valid` object var
1287
+	 *
1288
+	 * @return void
1289
+	 */
1290
+	function validate() {
1303 1291
 
1304
-        /**
1305
-         * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions.
1306
-         * You can enter whatever you want!
1307
-         * We try validating, and customize the results using `self::custom_validation()`
1308
-         */
1309
-        add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4);
1292
+		/**
1293
+		 * If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry
1294
+		 * GF User Registration Add-on version > 3.x has a different class name
1295
+		 * @since 1.16.2
1296
+		 */
1297
+		if ( class_exists( 'GF_User_Registration' ) ) {
1298
+			remove_filter( 'gform_validation', array( GF_User_Registration::get_instance(), 'validate' ) );
1299
+		} else  if ( class_exists( 'GFUser' ) ) {
1300
+			remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) );
1301
+		}
1310 1302
 
1311
-        // Needed by the validate funtion
1312
-        $failed_validation_page = NULL;
1313
-        $field_values = RGForms::post( 'gform_field_values' );
1314 1303
 
1315
-        // Prevent entry limit from running when editing an entry, also
1316
-        // prevent form scheduling from preventing editing
1317
-        unset( $this->form['limitEntries'], $this->form['scheduleForm'] );
1304
+		/**
1305
+		 * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions.
1306
+		 * You can enter whatever you want!
1307
+		 * We try validating, and customize the results using `self::custom_validation()`
1308
+		 */
1309
+		add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4);
1318 1310
 
1319
-        // Hide fields depending on Edit Entry settings
1320
-        $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id );
1311
+		// Needed by the validate funtion
1312
+		$failed_validation_page = NULL;
1313
+		$field_values = RGForms::post( 'gform_field_values' );
1321 1314
 
1322
-        $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page );
1315
+		// Prevent entry limit from running when editing an entry, also
1316
+		// prevent form scheduling from preventing editing
1317
+		unset( $this->form['limitEntries'], $this->form['scheduleForm'] );
1323 1318
 
1324
-        remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 );
1325
-    }
1319
+		// Hide fields depending on Edit Entry settings
1320
+		$this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id );
1326 1321
 
1322
+		$this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page );
1327 1323
 
1328
-    /**
1329
-     * Make validation work for Edit Entry
1330
-     *
1331
-     * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end
1332
-     * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post
1333
-     * fields. This goes through all the fields and if they're an invalid post field, we
1334
-     * set them as valid. If there are still issues, we'll return false.
1335
-     *
1336
-     * @param  [type] $validation_results [description]
1337
-     * @return [type]                     [description]
1338
-     */
1339
-    function custom_validation( $validation_results ) {
1324
+		remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 );
1325
+	}
1326
+
1327
+
1328
+	/**
1329
+	 * Make validation work for Edit Entry
1330
+	 *
1331
+	 * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end
1332
+	 * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post
1333
+	 * fields. This goes through all the fields and if they're an invalid post field, we
1334
+	 * set them as valid. If there are still issues, we'll return false.
1335
+	 *
1336
+	 * @param  [type] $validation_results [description]
1337
+	 * @return [type]                     [description]
1338
+	 */
1339
+	function custom_validation( $validation_results ) {
1340 1340
 
1341
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results );
1341
+		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results );
1342 1342
 
1343
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
1343
+		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
1344 1344
 
1345
-        $gv_valid = true;
1345
+		$gv_valid = true;
1346 1346
 
1347
-        foreach ( $validation_results['form']['fields'] as $key => &$field ) {
1347
+		foreach ( $validation_results['form']['fields'] as $key => &$field ) {
1348 1348
 
1349
-            $value = RGFormsModel::get_field_value( $field );
1350
-            $field_type = RGFormsModel::get_input_type( $field );
1349
+			$value = RGFormsModel::get_field_value( $field );
1350
+			$field_type = RGFormsModel::get_input_type( $field );
1351 1351
 
1352
-            // Validate always
1353
-            switch ( $field_type ) {
1352
+			// Validate always
1353
+			switch ( $field_type ) {
1354 1354
 
1355 1355
 
1356
-                case 'fileupload' :
1357
-                case 'post_image':
1356
+				case 'fileupload' :
1357
+				case 'post_image':
1358 1358
 
1359
-                    // in case nothing is uploaded but there are already files saved
1360
-                    if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) {
1361
-                        $field->failed_validation = false;
1362
-                        unset( $field->validation_message );
1363
-                    }
1359
+					// in case nothing is uploaded but there are already files saved
1360
+					if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) {
1361
+						$field->failed_validation = false;
1362
+						unset( $field->validation_message );
1363
+					}
1364 1364
 
1365
-                    // validate if multi file upload reached max number of files [maxFiles] => 2
1366
-                    if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) {
1365
+					// validate if multi file upload reached max number of files [maxFiles] => 2
1366
+					if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) {
1367 1367
 
1368
-                        $input_name = 'input_' . $field->id;
1369
-                        //uploaded
1370
-                        $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array();
1368
+						$input_name = 'input_' . $field->id;
1369
+						//uploaded
1370
+						$file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array();
1371 1371
 
1372
-                        //existent
1373
-                        $entry = $this->get_entry();
1374
-                        $value = NULL;
1375
-                        if( isset( $entry[ $field->id ] ) ) {
1376
-                            $value = json_decode( $entry[ $field->id ], true );
1377
-                        }
1372
+						//existent
1373
+						$entry = $this->get_entry();
1374
+						$value = NULL;
1375
+						if( isset( $entry[ $field->id ] ) ) {
1376
+							$value = json_decode( $entry[ $field->id ], true );
1377
+						}
1378 1378
 
1379
-                        // count uploaded files and existent entry files
1380
-                        $count_files = count( $file_names ) + count( $value );
1379
+						// count uploaded files and existent entry files
1380
+						$count_files = count( $file_names ) + count( $value );
1381 1381
 
1382
-                        if( $count_files > $field->maxFiles ) {
1383
-                            $field->validation_message = __( 'Maximum number of files reached', 'gravityview' );
1384
-                            $field->failed_validation = 1;
1385
-                            $gv_valid = false;
1382
+						if( $count_files > $field->maxFiles ) {
1383
+							$field->validation_message = __( 'Maximum number of files reached', 'gravityview' );
1384
+							$field->failed_validation = 1;
1385
+							$gv_valid = false;
1386 1386
 
1387
-                            // in case of error make sure the newest upload files are removed from the upload input
1388
-                            GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null;
1389
-                        }
1387
+							// in case of error make sure the newest upload files are removed from the upload input
1388
+							GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null;
1389
+						}
1390 1390
 
1391
-                    }
1391
+					}
1392 1392
 
1393 1393
 
1394
-                    break;
1394
+					break;
1395 1395
 
1396
-            }
1396
+			}
1397 1397
 
1398
-            // This field has failed validation.
1399
-            if( !empty( $field->failed_validation ) ) {
1398
+			// This field has failed validation.
1399
+			if( !empty( $field->failed_validation ) ) {
1400 1400
 
1401
-                do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) );
1401
+				do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) );
1402 1402
 
1403
-                switch ( $field_type ) {
1403
+				switch ( $field_type ) {
1404 1404
 
1405
-                    // Captchas don't need to be re-entered.
1406
-                    case 'captcha':
1405
+					// Captchas don't need to be re-entered.
1406
+					case 'captcha':
1407 1407
 
1408
-                        // Post Image fields aren't editable, so we un-fail them.
1409
-                    case 'post_image':
1410
-                        $field->failed_validation = false;
1411
-                        unset( $field->validation_message );
1412
-                        break;
1408
+						// Post Image fields aren't editable, so we un-fail them.
1409
+					case 'post_image':
1410
+						$field->failed_validation = false;
1411
+						unset( $field->validation_message );
1412
+						break;
1413 1413
 
1414
-                }
1414
+				}
1415 1415
 
1416
-                // You can't continue inside a switch, so we do it after.
1417
-                if( empty( $field->failed_validation ) ) {
1418
-                    continue;
1419
-                }
1416
+				// You can't continue inside a switch, so we do it after.
1417
+				if( empty( $field->failed_validation ) ) {
1418
+					continue;
1419
+				}
1420 1420
 
1421
-                // checks if the No Duplicates option is not validating entry against itself, since
1422
-                // we're editing a stored entry, it would also assume it's a duplicate.
1423
-                if( !empty( $field->noDuplicates ) ) {
1421
+				// checks if the No Duplicates option is not validating entry against itself, since
1422
+				// we're editing a stored entry, it would also assume it's a duplicate.
1423
+				if( !empty( $field->noDuplicates ) ) {
1424 1424
 
1425
-                    $entry = $this->get_entry();
1425
+					$entry = $this->get_entry();
1426 1426
 
1427
-                    // If the value of the entry is the same as the stored value
1428
-                    // Then we can assume it's not a duplicate, it's the same.
1429
-                    if( !empty( $entry ) && $value == $entry[ $field->id ] ) {
1430
-                        //if value submitted was not changed, then don't validate
1431
-                        $field->failed_validation = false;
1427
+					// If the value of the entry is the same as the stored value
1428
+					// Then we can assume it's not a duplicate, it's the same.
1429
+					if( !empty( $entry ) && $value == $entry[ $field->id ] ) {
1430
+						//if value submitted was not changed, then don't validate
1431
+						$field->failed_validation = false;
1432 1432
 
1433
-                        unset( $field->validation_message );
1433
+						unset( $field->validation_message );
1434 1434
 
1435
-                        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry );
1435
+						do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry );
1436 1436
 
1437
-                        continue;
1438
-                    }
1439
-                }
1437
+						continue;
1438
+					}
1439
+				}
1440 1440
 
1441
-                // if here then probably we are facing the validation 'At least one field must be filled out'
1442
-                if( GFFormDisplay::is_empty( $field, $this->form_id  ) && empty( $field->isRequired ) ) {
1443
-                    unset( $field->validation_message );
1444
-	                $field->validation_message = false;
1445
-                    continue;
1446
-                }
1441
+				// if here then probably we are facing the validation 'At least one field must be filled out'
1442
+				if( GFFormDisplay::is_empty( $field, $this->form_id  ) && empty( $field->isRequired ) ) {
1443
+					unset( $field->validation_message );
1444
+					$field->validation_message = false;
1445
+					continue;
1446
+				}
1447 1447
 
1448
-                $gv_valid = false;
1448
+				$gv_valid = false;
1449 1449
 
1450
-            }
1450
+			}
1451 1451
 
1452
-        }
1452
+		}
1453 1453
 
1454
-        $validation_results['is_valid'] = $gv_valid;
1454
+		$validation_results['is_valid'] = $gv_valid;
1455 1455
 
1456
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results );
1456
+		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results );
1457 1457
 
1458
-        // We'll need this result when rendering the form ( on GFFormDisplay::get_form )
1459
-        $this->form_after_validation = $validation_results['form'];
1458
+		// We'll need this result when rendering the form ( on GFFormDisplay::get_form )
1459
+		$this->form_after_validation = $validation_results['form'];
1460 1460
 
1461
-        return $validation_results;
1462
-    }
1461
+		return $validation_results;
1462
+	}
1463 1463
 
1464 1464
 
1465
-    /**
1466
-     * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()!
1467
-     * Get the current entry and set it if it's not yet set.
1468
-     * @return array Gravity Forms entry array
1469
-     */
1470
-    public function get_entry() {
1465
+	/**
1466
+	 * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()!
1467
+	 * Get the current entry and set it if it's not yet set.
1468
+	 * @return array Gravity Forms entry array
1469
+	 */
1470
+	public function get_entry() {
1471 1471
 
1472
-        if( empty( $this->entry ) ) {
1473
-            // Get the database value of the entry that's being edited
1474
-            $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() );
1475
-        }
1472
+		if( empty( $this->entry ) ) {
1473
+			// Get the database value of the entry that's being edited
1474
+			$this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() );
1475
+		}
1476 1476
 
1477
-        return $this->entry;
1478
-    }
1477
+		return $this->entry;
1478
+	}
1479 1479
 
1480 1480
 
1481 1481
 
1482
-    // --- Filters
1482
+	// --- Filters
1483 1483
 
1484
-    /**
1485
-     * Get the Edit Entry fields as configured in the View
1486
-     *
1487
-     * @since 1.8
1488
-     *
1489
-     * @param int $view_id
1490
-     *
1491
-     * @return array Array of fields that are configured in the Edit tab in the Admin
1492
-     */
1493
-    private function get_configured_edit_fields( $form, $view_id ) {
1484
+	/**
1485
+	 * Get the Edit Entry fields as configured in the View
1486
+	 *
1487
+	 * @since 1.8
1488
+	 *
1489
+	 * @param int $view_id
1490
+	 *
1491
+	 * @return array Array of fields that are configured in the Edit tab in the Admin
1492
+	 */
1493
+	private function get_configured_edit_fields( $form, $view_id ) {
1494 1494
 
1495
-        // Get all fields for form
1496
-        $properties = GravityView_View_Data::getInstance()->get_fields( $view_id );
1495
+		// Get all fields for form
1496
+		$properties = GravityView_View_Data::getInstance()->get_fields( $view_id );
1497 1497
 
1498
-        // If edit tab not yet configured, show all fields
1499
-        $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL;
1498
+		// If edit tab not yet configured, show all fields
1499
+		$edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL;
1500 1500
 
1501
-        // Show hidden fields as text fields
1502
-        $form = $this->fix_survey_fields( $form );
1501
+		// Show hidden fields as text fields
1502
+		$form = $this->fix_survey_fields( $form );
1503 1503
 
1504
-        // Hide fields depending on admin settings
1505
-        $fields = $this->filter_fields( $form['fields'], $edit_fields );
1504
+		// Hide fields depending on admin settings
1505
+		$fields = $this->filter_fields( $form['fields'], $edit_fields );
1506 1506
 
1507
-	    // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't.
1508
-	    $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id );
1507
+		// If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't.
1508
+		$fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id );
1509 1509
 
1510
-        /**
1511
-         * @filter `gravityview/edit_entry/form_fields` Modify the fields displayed in Edit Entry form
1512
-         * @since 1.17
1513
-         * @param GF_Field[] $fields Gravity Forms form fields
1514
-         * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration
1515
-         * @param array $form GF Form array (`fields` key modified to have only fields configured to show in Edit Entry)
1516
-         * @param int $view_id View ID
1517
-         */
1518
-        $fields = apply_filters( 'gravityview/edit_entry/form_fields', $fields, $edit_fields, $form, $view_id );
1510
+		/**
1511
+		 * @filter `gravityview/edit_entry/form_fields` Modify the fields displayed in Edit Entry form
1512
+		 * @since 1.17
1513
+		 * @param GF_Field[] $fields Gravity Forms form fields
1514
+		 * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration
1515
+		 * @param array $form GF Form array (`fields` key modified to have only fields configured to show in Edit Entry)
1516
+		 * @param int $view_id View ID
1517
+		 */
1518
+		$fields = apply_filters( 'gravityview/edit_entry/form_fields', $fields, $edit_fields, $form, $view_id );
1519 1519
 
1520
-        return $fields;
1521
-    }
1520
+		return $fields;
1521
+	}
1522 1522
 
1523
-    /**
1524
-     * Make sure Survey fields accept pre-populating values; otherwise existing values won't be filled-in
1525
-     *
1526
-     * @since 1.16.4
1527
-     *
1528
-     * @param array $form
1529
-     *
1530
-     * @return array Form, with all fields set to `allowsPrepopulate => true`
1531
-     */
1532
-    private function fix_survey_fields( $form ) {
1523
+	/**
1524
+	 * Make sure Survey fields accept pre-populating values; otherwise existing values won't be filled-in
1525
+	 *
1526
+	 * @since 1.16.4
1527
+	 *
1528
+	 * @param array $form
1529
+	 *
1530
+	 * @return array Form, with all fields set to `allowsPrepopulate => true`
1531
+	 */
1532
+	private function fix_survey_fields( $form ) {
1533 1533
 
1534
-        /** @var GF_Field $field */
1535
-        foreach( $form['fields'] as &$field ) {
1536
-            $field->allowsPrepopulate = true;
1537
-        }
1534
+		/** @var GF_Field $field */
1535
+		foreach( $form['fields'] as &$field ) {
1536
+			$field->allowsPrepopulate = true;
1537
+		}
1538 1538
 
1539
-        return $form;
1540
-    }
1539
+		return $form;
1540
+	}
1541 1541
     
1542 1542
 
1543
-    /**
1544
-     * Filter area fields based on specified conditions
1545
-     *  - This filter removes the fields that have calculation configured
1546
-     *
1547
-     * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps
1548
-     * @access private
1549
-     * @param GF_Field[] $fields
1550
-     * @param array $configured_fields
1551
-     * @since  1.5
1552
-     * @return array $fields
1553
-     */
1554
-    private function filter_fields( $fields, $configured_fields ) {
1555
-
1556
-        if( empty( $fields ) || !is_array( $fields ) ) {
1557
-            return $fields;
1558
-        }
1559
-
1560
-        $edit_fields = array();
1561
-
1562
-        $field_type_blacklist = array(
1563
-            'page',
1564
-        );
1565
-
1566
-	    /**
1567
-	     * @filter `gravityview/edit_entry/hide-product-fields` Hide product fields from being editable.
1568
-	     * @since 1.9.1
1569
-         * @param boolean $hide_product_fields Whether to hide product fields in the editor.  Default: false
1570
-	     */
1571
-	    $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) );
1572
-
1573
-	    if( $hide_product_fields ) {
1574
-		    $field_type_blacklist[] = 'option';
1575
-		    $field_type_blacklist[] = 'quantity';
1576
-            $field_type_blacklist[] = 'product';
1577
-            $field_type_blacklist[] = 'total';
1578
-            $field_type_blacklist[] = 'shipping';
1579
-            $field_type_blacklist[] = 'calculation';
1580
-	    }
1581
-
1582
-        // First, remove blacklist or calculation fields
1583
-        foreach ( $fields as $key => $field ) {
1584
-
1585
-            // Remove the fields that have calculation properties and keep them to be used later
1586
-            // @since 1.16.2
1587
-            if( $field->has_calculation() ) {
1588
-                $this->fields_with_calculation[] = $field;
1589
-                // don't remove the calculation fields on form render.
1590
-            }
1591
-
1592
-            // process total field after all fields have been saved
1593
-            if ( $field->type == 'total' ) {
1594
-                $this->total_fields[] = $field;
1595
-                unset( $fields[ $key ] );
1596
-            }
1597
-
1598
-            if( in_array( $field->type, $field_type_blacklist ) ) {
1599
-                unset( $fields[ $key ] );
1600
-            }
1601
-        }
1602
-
1603
-        // The Edit tab has not been configured, so we return all fields by default.
1604
-        if( empty( $configured_fields ) ) {
1605
-            return $fields;
1606
-        }
1607
-
1608
-        // The edit tab has been configured, so we loop through to configured settings
1609
-        foreach ( $configured_fields as $configured_field ) {
1610
-
1611
-	        /** @var GF_Field $field */
1612
-	        foreach ( $fields as $field ) {
1613
-
1614
-                if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) {
1615
-                    $edit_fields[] = $this->merge_field_properties( $field, $configured_field );
1616
-                    break;
1617
-                }
1618
-
1619
-            }
1620
-
1621
-        }
1622
-
1623
-        return $edit_fields;
1624
-
1625
-    }
1626
-
1627
-    /**
1628
-     * Override GF Form field properties with the ones defined on the View
1629
-     * @param  GF_Field $field GF Form field object
1630
-     * @param  array $setting  GV field options
1631
-     * @since  1.5
1632
-     * @return array
1633
-     */
1634
-    private function merge_field_properties( $field, $field_setting ) {
1635
-
1636
-        $return_field = $field;
1637
-
1638
-        if( empty( $field_setting['show_label'] ) ) {
1639
-            $return_field->label = '';
1640
-        } elseif ( !empty( $field_setting['custom_label'] ) ) {
1641
-            $return_field->label = $field_setting['custom_label'];
1642
-        }
1643
-
1644
-        if( !empty( $field_setting['custom_class'] ) ) {
1645
-            $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] );
1646
-        }
1647
-
1648
-        /**
1649
-         * Normalize page numbers - avoid conflicts with page validation
1650
-         * @since 1.6
1651
-         */
1652
-        $return_field->pageNumber = 1;
1653
-
1654
-        return $return_field;
1655
-
1656
-    }
1657
-
1658
-    /**
1659
-     * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property
1660
-     *
1661
-     * @since 1.9.1
1662
-     *
1663
-     * @param array|GF_Field[] $fields Gravity Forms form fields
1664
-     * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration
1665
-     * @param array $form GF Form array
1666
-     * @param int $view_id View ID
1667
-     *
1668
-     * @return array Possibly modified form array
1669
-     */
1670
-    function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) {
1671
-
1672
-	    /**
1673
-         * @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
1674
-	     * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators.
1675
-	     * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions
1676
-	     * @since 1.9.1
1677
-	     * @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.
1678
-	     * @param array $form GF Form array
1679
-	     * @param int $view_id View ID
1680
-	     */
1681
-	    $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id );
1682
-
1683
-	    if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) {
1684
-            foreach( $fields as $k => $field ) {
1685
-                if( $field->adminOnly ) {
1686
-                    unset( $fields[ $k ] );
1687
-                }
1688
-            }
1689
-            return $fields;
1690
-        }
1691
-
1692
-	    foreach( $fields as &$field ) {
1693
-		    $field->adminOnly = false;
1694
-        }
1695
-
1696
-        return $fields;
1697
-    }
1698
-
1699
-    // --- Conditional Logic
1700
-
1701
-    /**
1702
-     * Remove the conditional logic rules from the form button and the form fields, if needed.
1703
-     *
1704
-     * @since 1.9
1705
-     *
1706
-     * @param array $form Gravity Forms form
1707
-     * @return array Modified form, if not using Conditional Logic
1708
-     */
1709
-    function filter_conditional_logic( $form ) {
1710
-
1711
-        /**
1712
-         * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields?
1713
-         * @since 1.9
1714
-         * @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
1715
-         * @param array $form Gravity Forms form
1716
-         */
1717
-        $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form );
1718
-
1719
-        if( $use_conditional_logic ) {
1720
-            return $form;
1721
-        }
1722
-
1723
-        foreach( $form['fields'] as &$field ) {
1724
-            /* @var GF_Field $field */
1725
-            $field->conditionalLogic = null;
1726
-        }
1727
-
1728
-        unset( $form['button']['conditionalLogic'] );
1729
-
1730
-        return $form;
1731
-
1732
-    }
1733
-
1734
-    /**
1735
-     * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen
1736
-     *
1737
-     * @since 1.9
1738
-     *
1739
-     * @param $has_conditional_logic
1740
-     * @param $form
1741
-     * @return mixed|void
1742
-     */
1743
-    function manage_conditional_logic( $has_conditional_logic, $form ) {
1744
-
1745
-        if( ! $this->is_edit_entry() ) {
1746
-            return $has_conditional_logic;
1747
-        }
1748
-
1749
-        return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form );
1750
-    }
1751
-
1752
-
1753
-    // --- User checks and nonces
1754
-
1755
-    /**
1756
-     * Check if the user can edit the entry
1757
-     *
1758
-     * - Is the nonce valid?
1759
-     * - Does the user have the right caps for the entry
1760
-     * - Is the entry in the trash?
1761
-     *
1762
-     * @todo Move to GVCommon
1763
-     *
1764
-     * @param  boolean $echo Show error messages in the form?
1765
-     * @return boolean        True: can edit form. False: nope.
1766
-     */
1767
-    function user_can_edit_entry( $echo = false ) {
1768
-
1769
-        $error = NULL;
1770
-
1771
-        /**
1772
-         *  1. Permalinks are turned off
1773
-         *  2. There are two entries embedded using oEmbed
1774
-         *  3. One of the entries has just been saved
1775
-         */
1776
-        if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) {
1777
-
1778
-            $error = true;
1779
-
1780
-        }
1781
-
1782
-        if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) {
1783
-
1784
-            $error = true;
1785
-
1786
-        } elseif( ! $this->verify_nonce() ) {
1787
-
1788
-            /**
1789
-             * If the Entry is embedded, there may be two entries on the same page.
1790
-             * If that's the case, and one is being edited, the other should fail gracefully and not display an error.
1791
-             */
1792
-            if( GravityView_oEmbed::getInstance()->get_entry_id() ) {
1793
-                $error = true;
1794
-            } else {
1795
-                $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview');
1796
-            }
1543
+	/**
1544
+	 * Filter area fields based on specified conditions
1545
+	 *  - This filter removes the fields that have calculation configured
1546
+	 *
1547
+	 * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps
1548
+	 * @access private
1549
+	 * @param GF_Field[] $fields
1550
+	 * @param array $configured_fields
1551
+	 * @since  1.5
1552
+	 * @return array $fields
1553
+	 */
1554
+	private function filter_fields( $fields, $configured_fields ) {
1555
+
1556
+		if( empty( $fields ) || !is_array( $fields ) ) {
1557
+			return $fields;
1558
+		}
1559
+
1560
+		$edit_fields = array();
1561
+
1562
+		$field_type_blacklist = array(
1563
+			'page',
1564
+		);
1565
+
1566
+		/**
1567
+		 * @filter `gravityview/edit_entry/hide-product-fields` Hide product fields from being editable.
1568
+		 * @since 1.9.1
1569
+		 * @param boolean $hide_product_fields Whether to hide product fields in the editor.  Default: false
1570
+		 */
1571
+		$hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) );
1572
+
1573
+		if( $hide_product_fields ) {
1574
+			$field_type_blacklist[] = 'option';
1575
+			$field_type_blacklist[] = 'quantity';
1576
+			$field_type_blacklist[] = 'product';
1577
+			$field_type_blacklist[] = 'total';
1578
+			$field_type_blacklist[] = 'shipping';
1579
+			$field_type_blacklist[] = 'calculation';
1580
+		}
1581
+
1582
+		// First, remove blacklist or calculation fields
1583
+		foreach ( $fields as $key => $field ) {
1584
+
1585
+			// Remove the fields that have calculation properties and keep them to be used later
1586
+			// @since 1.16.2
1587
+			if( $field->has_calculation() ) {
1588
+				$this->fields_with_calculation[] = $field;
1589
+				// don't remove the calculation fields on form render.
1590
+			}
1591
+
1592
+			// process total field after all fields have been saved
1593
+			if ( $field->type == 'total' ) {
1594
+				$this->total_fields[] = $field;
1595
+				unset( $fields[ $key ] );
1596
+			}
1597
+
1598
+			if( in_array( $field->type, $field_type_blacklist ) ) {
1599
+				unset( $fields[ $key ] );
1600
+			}
1601
+		}
1602
+
1603
+		// The Edit tab has not been configured, so we return all fields by default.
1604
+		if( empty( $configured_fields ) ) {
1605
+			return $fields;
1606
+		}
1607
+
1608
+		// The edit tab has been configured, so we loop through to configured settings
1609
+		foreach ( $configured_fields as $configured_field ) {
1610
+
1611
+			/** @var GF_Field $field */
1612
+			foreach ( $fields as $field ) {
1613
+
1614
+				if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) {
1615
+					$edit_fields[] = $this->merge_field_properties( $field, $configured_field );
1616
+					break;
1617
+				}
1797 1618
 
1798
-        }
1799
-
1800
-        if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) {
1801
-            $error = __( 'You do not have permission to edit this entry.', 'gravityview');
1802
-        }
1803
-
1804
-        if( $this->entry['status'] === 'trash' ) {
1805
-            $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' );
1806
-        }
1619
+			}
1807 1620
 
1808
-        // No errors; everything's fine here!
1809
-        if( empty( $error ) ) {
1810
-            return true;
1811
-        }
1621
+		}
1812 1622
 
1813
-        if( $echo && $error !== true ) {
1623
+		return $edit_fields;
1814 1624
 
1815
-	        $error = esc_html( $error );
1625
+	}
1816 1626
 
1817
-	        /**
1818
-	         * @since 1.9
1819
-	         */
1820
-	        if ( ! empty( $this->entry ) ) {
1821
-		        $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;" ) );
1822
-	        }
1627
+	/**
1628
+	 * Override GF Form field properties with the ones defined on the View
1629
+	 * @param  GF_Field $field GF Form field object
1630
+	 * @param  array $setting  GV field options
1631
+	 * @since  1.5
1632
+	 * @return array
1633
+	 */
1634
+	private function merge_field_properties( $field, $field_setting ) {
1823 1635
 
1824
-            echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error');
1825
-        }
1636
+		$return_field = $field;
1826 1637
 
1827
-        do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error );
1638
+		if( empty( $field_setting['show_label'] ) ) {
1639
+			$return_field->label = '';
1640
+		} elseif ( !empty( $field_setting['custom_label'] ) ) {
1641
+			$return_field->label = $field_setting['custom_label'];
1642
+		}
1828 1643
 
1829
-        return false;
1830
-    }
1644
+		if( !empty( $field_setting['custom_class'] ) ) {
1645
+			$return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] );
1646
+		}
1831 1647
 
1648
+		/**
1649
+		 * Normalize page numbers - avoid conflicts with page validation
1650
+		 * @since 1.6
1651
+		 */
1652
+		$return_field->pageNumber = 1;
1832 1653
 
1833
-    /**
1834
-     * Check whether a field is editable by the current user, and optionally display an error message
1835
-     * @uses  GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities
1836
-     * @param  array  $field Field or field settings array
1837
-     * @param  boolean $echo  Whether to show error message telling user they aren't allowed
1838
-     * @return boolean         True: user can edit the current field; False: nope, they can't.
1839
-     */
1840
-    private function user_can_edit_field( $field, $echo = false ) {
1841
-
1842
-        $error = NULL;
1654
+		return $return_field;
1843 1655
 
1844
-        if( ! $this->check_user_cap_edit_field( $field ) ) {
1845
-            $error = __( 'You do not have permission to edit this field.', 'gravityview');
1846
-        }
1656
+	}
1847 1657
 
1848
-        // No errors; everything's fine here!
1849
-        if( empty( $error ) ) {
1850
-            return true;
1851
-        }
1658
+	/**
1659
+	 * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property
1660
+	 *
1661
+	 * @since 1.9.1
1662
+	 *
1663
+	 * @param array|GF_Field[] $fields Gravity Forms form fields
1664
+	 * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration
1665
+	 * @param array $form GF Form array
1666
+	 * @param int $view_id View ID
1667
+	 *
1668
+	 * @return array Possibly modified form array
1669
+	 */
1670
+	function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) {
1671
+
1672
+		/**
1673
+		 * @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
1674
+		 * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators.
1675
+		 * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions
1676
+		 * @since 1.9.1
1677
+		 * @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.
1678
+		 * @param array $form GF Form array
1679
+		 * @param int $view_id View ID
1680
+		 */
1681
+		$use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id );
1682
+
1683
+		if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) {
1684
+			foreach( $fields as $k => $field ) {
1685
+				if( $field->adminOnly ) {
1686
+					unset( $fields[ $k ] );
1687
+				}
1688
+			}
1689
+			return $fields;
1690
+		}
1852 1691
 
1853
-        if( $echo ) {
1854
-            echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error');
1855
-        }
1856
-
1857
-        do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error );
1692
+		foreach( $fields as &$field ) {
1693
+			$field->adminOnly = false;
1694
+		}
1858 1695
 
1859
-        return false;
1696
+		return $fields;
1697
+	}
1860 1698
 
1861
-    }
1699
+	// --- Conditional Logic
1862 1700
 
1701
+	/**
1702
+	 * Remove the conditional logic rules from the form button and the form fields, if needed.
1703
+	 *
1704
+	 * @since 1.9
1705
+	 *
1706
+	 * @param array $form Gravity Forms form
1707
+	 * @return array Modified form, if not using Conditional Logic
1708
+	 */
1709
+	function filter_conditional_logic( $form ) {
1863 1710
 
1864
-    /**
1865
-     * checks if user has permissions to edit a specific field
1866
-     *
1867
-     * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!!
1868
-     *
1869
-     * @param  [type] $field [description]
1870
-     * @return bool
1871
-     */
1872
-    private function check_user_cap_edit_field( $field ) {
1711
+		/**
1712
+		 * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields?
1713
+		 * @since 1.9
1714
+		 * @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
1715
+		 * @param array $form Gravity Forms form
1716
+		 */
1717
+		$use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form );
1873 1718
 
1874
-        // If they can edit any entries (as defined in Gravity Forms), we're good.
1875
-        if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) {
1876
-            return true;
1877
-        }
1719
+		if( $use_conditional_logic ) {
1720
+			return $form;
1721
+		}
1878 1722
 
1879
-        $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false;
1723
+		foreach( $form['fields'] as &$field ) {
1724
+			/* @var GF_Field $field */
1725
+			$field->conditionalLogic = null;
1726
+		}
1880 1727
 
1881
-        // If the field has custom editing capaibilities set, check those
1882
-        if( $field_cap ) {
1883
-            return GVCommon::has_cap( $field['allow_edit_cap'] );
1884
-        }
1885
-
1886
-        return false;
1887
-    }
1728
+		unset( $form['button']['conditionalLogic'] );
1888 1729
 
1730
+		return $form;
1889 1731
 
1890
-    /**
1891
-     * Is the current nonce valid for editing the entry?
1892
-     * @return boolean
1893
-     */
1894
-    public function verify_nonce() {
1732
+	}
1733
+
1734
+	/**
1735
+	 * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen
1736
+	 *
1737
+	 * @since 1.9
1738
+	 *
1739
+	 * @param $has_conditional_logic
1740
+	 * @param $form
1741
+	 * @return mixed|void
1742
+	 */
1743
+	function manage_conditional_logic( $has_conditional_logic, $form ) {
1895 1744
 
1896
-        // Verify form submitted for editing single
1897
-        if( $this->is_edit_entry_submission() ) {
1898
-            $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field );
1899
-        }
1745
+		if( ! $this->is_edit_entry() ) {
1746
+			return $has_conditional_logic;
1747
+		}
1900 1748
 
1901
-        // Verify
1902
-        else if( ! $this->is_edit_entry() ) {
1903
-            $valid = false;
1904
-        }
1749
+		return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form );
1750
+	}
1751
+
1752
+
1753
+	// --- User checks and nonces
1754
+
1755
+	/**
1756
+	 * Check if the user can edit the entry
1757
+	 *
1758
+	 * - Is the nonce valid?
1759
+	 * - Does the user have the right caps for the entry
1760
+	 * - Is the entry in the trash?
1761
+	 *
1762
+	 * @todo Move to GVCommon
1763
+	 *
1764
+	 * @param  boolean $echo Show error messages in the form?
1765
+	 * @return boolean        True: can edit form. False: nope.
1766
+	 */
1767
+	function user_can_edit_entry( $echo = false ) {
1905 1768
 
1906
-        else {
1907
-            $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key );
1908
-        }
1769
+		$error = NULL;
1909 1770
 
1910
-        /**
1911
-         * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid.
1912
-         * @since 1.13
1913
-         * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated
1914
-         * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry
1915
-         */
1916
-        $valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field );
1771
+		/**
1772
+		 *  1. Permalinks are turned off
1773
+		 *  2. There are two entries embedded using oEmbed
1774
+		 *  3. One of the entries has just been saved
1775
+		 */
1776
+		if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) {
1917 1777
 
1918
-        return $valid;
1919
-    }
1778
+			$error = true;
1779
+
1780
+		}
1781
+
1782
+		if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) {
1783
+
1784
+			$error = true;
1785
+
1786
+		} elseif( ! $this->verify_nonce() ) {
1787
+
1788
+			/**
1789
+			 * If the Entry is embedded, there may be two entries on the same page.
1790
+			 * If that's the case, and one is being edited, the other should fail gracefully and not display an error.
1791
+			 */
1792
+			if( GravityView_oEmbed::getInstance()->get_entry_id() ) {
1793
+				$error = true;
1794
+			} else {
1795
+				$error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview');
1796
+			}
1797
+
1798
+		}
1799
+
1800
+		if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) {
1801
+			$error = __( 'You do not have permission to edit this entry.', 'gravityview');
1802
+		}
1803
+
1804
+		if( $this->entry['status'] === 'trash' ) {
1805
+			$error = __('You cannot edit the entry; it is in the trash.', 'gravityview' );
1806
+		}
1807
+
1808
+		// No errors; everything's fine here!
1809
+		if( empty( $error ) ) {
1810
+			return true;
1811
+		}
1812
+
1813
+		if( $echo && $error !== true ) {
1814
+
1815
+			$error = esc_html( $error );
1816
+
1817
+			/**
1818
+			 * @since 1.9
1819
+			 */
1820
+			if ( ! empty( $this->entry ) ) {
1821
+				$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;" ) );
1822
+			}
1823
+
1824
+			echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error');
1825
+		}
1826
+
1827
+		do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error );
1828
+
1829
+		return false;
1830
+	}
1831
+
1832
+
1833
+	/**
1834
+	 * Check whether a field is editable by the current user, and optionally display an error message
1835
+	 * @uses  GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities
1836
+	 * @param  array  $field Field or field settings array
1837
+	 * @param  boolean $echo  Whether to show error message telling user they aren't allowed
1838
+	 * @return boolean         True: user can edit the current field; False: nope, they can't.
1839
+	 */
1840
+	private function user_can_edit_field( $field, $echo = false ) {
1841
+
1842
+		$error = NULL;
1843
+
1844
+		if( ! $this->check_user_cap_edit_field( $field ) ) {
1845
+			$error = __( 'You do not have permission to edit this field.', 'gravityview');
1846
+		}
1847
+
1848
+		// No errors; everything's fine here!
1849
+		if( empty( $error ) ) {
1850
+			return true;
1851
+		}
1852
+
1853
+		if( $echo ) {
1854
+			echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error');
1855
+		}
1856
+
1857
+		do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error );
1858
+
1859
+		return false;
1860
+
1861
+	}
1862
+
1863
+
1864
+	/**
1865
+	 * checks if user has permissions to edit a specific field
1866
+	 *
1867
+	 * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!!
1868
+	 *
1869
+	 * @param  [type] $field [description]
1870
+	 * @return bool
1871
+	 */
1872
+	private function check_user_cap_edit_field( $field ) {
1873
+
1874
+		// If they can edit any entries (as defined in Gravity Forms), we're good.
1875
+		if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) {
1876
+			return true;
1877
+		}
1878
+
1879
+		$field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false;
1880
+
1881
+		// If the field has custom editing capaibilities set, check those
1882
+		if( $field_cap ) {
1883
+			return GVCommon::has_cap( $field['allow_edit_cap'] );
1884
+		}
1885
+
1886
+		return false;
1887
+	}
1888
+
1889
+
1890
+	/**
1891
+	 * Is the current nonce valid for editing the entry?
1892
+	 * @return boolean
1893
+	 */
1894
+	public function verify_nonce() {
1895
+
1896
+		// Verify form submitted for editing single
1897
+		if( $this->is_edit_entry_submission() ) {
1898
+			$valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field );
1899
+		}
1900
+
1901
+		// Verify
1902
+		else if( ! $this->is_edit_entry() ) {
1903
+			$valid = false;
1904
+		}
1905
+
1906
+		else {
1907
+			$valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key );
1908
+		}
1909
+
1910
+		/**
1911
+		 * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid.
1912
+		 * @since 1.13
1913
+		 * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated
1914
+		 * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry
1915
+		 */
1916
+		$valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field );
1917
+
1918
+		return $valid;
1919
+	}
1920 1920
 
1921 1921
 
1922 1922
 
Please login to merge, or discard this patch.
Spacing   +229 added lines, -229 removed lines patch added patch discarded remove patch
@@ -119,16 +119,16 @@  discard block
 block discarded – undo
119 119
     function load() {
120 120
 
121 121
         /** @define "GRAVITYVIEW_DIR" "../../../" */
122
-        include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' );
122
+        include_once( GRAVITYVIEW_DIR . 'includes/class-admin-approve-entries.php' );
123 123
 
124 124
         // Don't display an embedded form when editing an entry
125 125
         add_action( 'wp_head', array( $this, 'prevent_render_form' ) );
126 126
         add_action( 'wp_footer', array( $this, 'prevent_render_form' ) );
127 127
 
128 128
         // Stop Gravity Forms processing what is ours!
129
-        add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 );
129
+        add_filter( 'wp', array( $this, 'prevent_maybe_process_form' ), 8 );
130 130
 
131
-        add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') );
131
+        add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry' ) );
132 132
 
133 133
         add_action( 'gravityview_edit_entry', array( $this, 'init' ) );
134 134
 
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
         add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 );
140 140
 
141 141
         // Add fields expected by GFFormDisplay::validate()
142
-        add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') );
142
+        add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation' ) );
143 143
 
144 144
     }
145 145
 
@@ -154,8 +154,8 @@  discard block
 block discarded – undo
154 154
      * @return void
155 155
      */
156 156
     function prevent_render_form() {
157
-        if( $this->is_edit_entry() ) {
158
-            if( 'wp_head' === current_filter() ) {
157
+        if ( $this->is_edit_entry() ) {
158
+            if ( 'wp_head' === current_filter() ) {
159 159
                 add_filter( 'gform_shortcode_form', '__return_empty_string' );
160 160
             } else {
161 161
                 remove_filter( 'gform_shortcode_form', '__return_empty_string' );
@@ -170,10 +170,10 @@  discard block
 block discarded – undo
170 170
      */
171 171
     function prevent_maybe_process_form() {
172 172
 
173
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
173
+        do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
174 174
 
175
-        if( $this->is_edit_entry_submission() && $this->verify_nonce() ) {
176
-            remove_action( 'wp',  array( 'RGForms', 'maybe_process_form'), 9 );
175
+        if ( $this->is_edit_entry_submission() && $this->verify_nonce() ) {
176
+            remove_action( 'wp', array( 'RGForms', 'maybe_process_form' ), 9 );
177 177
         }
178 178
     }
179 179
 
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
      */
184 184
     public function is_edit_entry() {
185 185
 
186
-        $gf_page = function_exists('rgpost') && ( 'entry' === rgget( 'view' ) && isset( $_GET['edit'] ) );
186
+        $gf_page = function_exists( 'rgpost' ) && ( 'entry' === rgget( 'view' ) && isset( $_GET[ 'edit' ] ) );
187 187
 
188 188
         return $gf_page;
189 189
     }
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 	 * @return boolean
195 195
 	 */
196 196
 	public function is_edit_entry_submission() {
197
-		return !empty( $_POST[ self::$nonce_field ] );
197
+		return ! empty( $_POST[ self::$nonce_field ] );
198 198
 	}
199 199
 
200 200
     /**
@@ -205,15 +205,15 @@  discard block
 block discarded – undo
205 205
 
206 206
 
207 207
         $entries = $gravityview_view->getEntries();
208
-	    self::$original_entry = $entries[0];
209
-	    $this->entry = $entries[0];
208
+	    self::$original_entry = $entries[ 0 ];
209
+	    $this->entry = $entries[ 0 ];
210 210
 
211 211
         self::$original_form = $gravityview_view->getForm();
212 212
         $this->form = $gravityview_view->getForm();
213 213
         $this->form_id = $gravityview_view->getFormId();
214 214
         $this->view_id = $gravityview_view->getViewId();
215 215
 
216
-        self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] );
216
+        self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry[ 'id' ] );
217 217
     }
218 218
 
219 219
 
@@ -233,12 +233,12 @@  discard block
 block discarded – undo
233 233
         $this->setup_vars();
234 234
 
235 235
         // Multiple Views embedded, don't proceed if nonce fails
236
-        if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) {
236
+        if ( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET[ 'edit' ], self::$nonce_key ) ) {
237 237
             return;
238 238
         }
239 239
 
240 240
         // Sorry, you're not allowed here.
241
-        if( false === $this->user_can_edit_entry( true ) ) {
241
+        if ( false === $this->user_can_edit_entry( true ) ) {
242 242
             return;
243 243
         }
244 244
 
@@ -258,9 +258,9 @@  discard block
 block discarded – undo
258 258
     function print_scripts() {
259 259
         $gravityview_view = GravityView_View::getInstance();
260 260
 
261
-        wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) );
261
+        wp_register_script( 'gform_gravityforms', GFCommon::get_base_url() . '/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) );
262 262
 
263
-        GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false);
263
+        GFFormDisplay::enqueue_form_scripts( $gravityview_view->getForm(), false );
264 264
 
265 265
         // Sack is required for images
266 266
         wp_print_scripts( array( 'sack', 'gform_gravityforms' ) );
@@ -272,32 +272,32 @@  discard block
 block discarded – undo
272 272
      */
273 273
     function process_save() {
274 274
 
275
-        if( empty( $_POST ) ) {
275
+        if ( empty( $_POST ) ) {
276 276
             return;
277 277
         }
278 278
 
279 279
         // Make sure the entry, view, and form IDs are all correct
280 280
         $valid = $this->verify_nonce();
281 281
 
282
-        if( !$valid ) {
283
-            do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' );
282
+        if ( ! $valid ) {
283
+            do_action( 'gravityview_log_error', __METHOD__ . ' Nonce validation failed.' );
284 284
             return;
285 285
         }
286 286
 
287
-        if( $this->entry['id'] !== $_POST['lid'] ) {
288
-            do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' );
287
+        if ( $this->entry[ 'id' ] !== $_POST[ 'lid' ] ) {
288
+            do_action( 'gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' );
289 289
             return;
290 290
         }
291 291
 
292
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
292
+        do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
293 293
 
294 294
         $this->process_save_process_files( $this->form_id );
295 295
 
296 296
         $this->validate();
297 297
 
298
-        if( $this->is_valid ) {
298
+        if ( $this->is_valid ) {
299 299
 
300
-            do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' );
300
+            do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' );
301 301
 
302 302
             /**
303 303
              * @hack This step is needed to unset the adminOnly from form fields, to add the calculation fields
@@ -307,12 +307,12 @@  discard block
 block discarded – undo
307 307
             /**
308 308
              * @hack to avoid the capability validation of the method save_lead for GF 1.9+
309 309
              */
310
-            unset( $_GET['page'] );
310
+            unset( $_GET[ 'page' ] );
311 311
 
312 312
             GFFormsModel::save_lead( $form, $this->entry );
313 313
 
314 314
             // If there's a post associated with the entry, process post fields
315
-            if( !empty( $this->entry['post_id'] ) ) {
315
+            if ( ! empty( $this->entry[ 'post_id' ] ) ) {
316 316
                 $this->maybe_update_post_fields( $form );
317 317
             }
318 318
 
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
              * @param array $form Gravity Forms form array
328 328
              * @param string $entry_id Numeric ID of the entry that was updated
329 329
              */
330
-            do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] );
330
+            do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry[ 'id' ] );
331 331
         }
332 332
 
333 333
     } // process_save
@@ -361,11 +361,11 @@  discard block
 block discarded – undo
361 361
      * @return mixed
362 362
      */
363 363
     public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) {
364
-        if( ! $this->is_edit_entry() ) {
364
+        if ( ! $this->is_edit_entry() ) {
365 365
             return $plupload_init;
366 366
         }
367 367
 
368
-        $plupload_init['gf_vars']['max_files'] = 0;
368
+        $plupload_init[ 'gf_vars' ][ 'max_files' ] = 0;
369 369
 
370 370
         return $plupload_init;
371 371
     }
@@ -379,19 +379,19 @@  discard block
 block discarded – undo
379 379
 
380 380
         $form = $this->form;
381 381
 
382
-        foreach( $form['fields'] as $k => &$field ) {
382
+        foreach ( $form[ 'fields' ] as $k => &$field ) {
383 383
 
384 384
             // Remove the fields with calculation formulas before save to avoid conflicts with GF logic
385 385
             // @since 1.16.3
386
-            if( $field->has_calculation() ) {
387
-                unset( $form['fields'][ $k ] );
386
+            if ( $field->has_calculation() ) {
387
+                unset( $form[ 'fields' ][ $k ] );
388 388
             }
389 389
 
390 390
             $field->adminOnly = false;
391 391
 
392
-            if( isset( $field->inputs ) && is_array( $field->inputs ) ) {
393
-                foreach( $field->inputs as $key => $input ) {
394
-                    $field->inputs[ $key ][ 'id' ] = (string)$input['id'];
392
+            if ( isset( $field->inputs ) && is_array( $field->inputs ) ) {
393
+                foreach ( $field->inputs as $key => $input ) {
394
+                    $field->inputs[ $key ][ 'id' ] = (string)$input[ 'id' ];
395 395
                 }
396 396
             }
397 397
         }
@@ -405,20 +405,20 @@  discard block
 block discarded – undo
405 405
         $update = false;
406 406
 
407 407
         // get the most up to date entry values
408
-        $entry = GFAPI::get_entry( $this->entry['id'] );
408
+        $entry = GFAPI::get_entry( $this->entry[ 'id' ] );
409 409
 
410
-        if( !empty( $this->fields_with_calculation ) ) {
410
+        if ( ! empty( $this->fields_with_calculation ) ) {
411 411
             $update = true;
412 412
             foreach ( $this->fields_with_calculation as $calc_field ) {
413 413
                 $inputs = $calc_field->get_entry_inputs();
414 414
                 if ( is_array( $inputs ) ) {
415 415
                     foreach ( $inputs as $input ) {
416
-                        $input_name = 'input_' . str_replace( '.', '_', $input['id'] );
417
-                        $entry[ strval( $input['id'] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry );
416
+                        $input_name = 'input_' . str_replace( '.', '_', $input[ 'id' ] );
417
+                        $entry[ strval( $input[ 'id' ] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry[ 'id' ], $entry );
418 418
                     }
419 419
                 } else {
420
-                    $input_name = 'input_' . str_replace( '.', '_', $calc_field->id);
421
-                    $entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry );
420
+                    $input_name = 'input_' . str_replace( '.', '_', $calc_field->id );
421
+                    $entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry[ 'id' ], $entry );
422 422
                 }
423 423
             }
424 424
 
@@ -428,16 +428,16 @@  discard block
 block discarded – undo
428 428
         if ( ! empty( $this->total_fields ) ) {
429 429
             $update = true;
430 430
             foreach ( $this->total_fields as $total_field ) {
431
-                $input_name = 'input_' . str_replace( '.', '_', $total_field->id);
432
-                $entry[ strval( $total_field->id ) ] = RGFormsModel::prepare_value( $form, $total_field, '', $input_name, $entry['id'], $entry );
431
+                $input_name = 'input_' . str_replace( '.', '_', $total_field->id );
432
+                $entry[ strval( $total_field->id ) ] = RGFormsModel::prepare_value( $form, $total_field, '', $input_name, $entry[ 'id' ], $entry );
433 433
             }
434 434
         }
435 435
 
436
-        if( $update ) {
436
+        if ( $update ) {
437 437
 
438 438
             $return_entry = GFAPI::update_entry( $entry );
439 439
 
440
-            if( is_wp_error( $return_entry ) ) {
440
+            if ( is_wp_error( $return_entry ) ) {
441 441
                 do_action( 'gravityview_log_error', 'Updating the entry calculation and total fields failed', $return_entry );
442 442
             } else {
443 443
                 do_action( 'gravityview_log_debug', 'Updating the entry calculation and total fields succeeded' );
@@ -468,18 +468,18 @@  discard block
 block discarded – undo
468 468
 
469 469
         $input_name = 'input_' . $field_id;
470 470
 
471
-        if ( !empty( $_FILES[ $input_name ]['name'] ) ) {
471
+        if ( ! empty( $_FILES[ $input_name ][ 'name' ] ) ) {
472 472
 
473 473
             // We have a new image
474 474
 
475
-            $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'] );
475
+            $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry[ 'id' ] );
476 476
 
477 477
             $ary = ! empty( $value ) ? explode( '|:|', $value ) : array();
478 478
             $img_url = rgar( $ary, 0 );
479 479
 
480
-            $img_title       = count( $ary ) > 1 ? $ary[1] : '';
481
-            $img_caption     = count( $ary ) > 2 ? $ary[2] : '';
482
-            $img_description = count( $ary ) > 3 ? $ary[3] : '';
480
+            $img_title       = count( $ary ) > 1 ? $ary[ 1 ] : '';
481
+            $img_caption     = count( $ary ) > 2 ? $ary[ 2 ] : '';
482
+            $img_description = count( $ary ) > 3 ? $ary[ 3 ] : '';
483 483
 
484 484
             $image_meta = array(
485 485
                 'post_excerpt' => $img_caption,
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 
489 489
             //adding title only if it is not empty. It will default to the file name if it is not in the array
490 490
             if ( ! empty( $img_title ) ) {
491
-                $image_meta['post_title'] = $img_title;
491
+                $image_meta[ 'post_title' ] = $img_title;
492 492
             }
493 493
 
494 494
             /**
@@ -503,22 +503,22 @@  discard block
 block discarded – undo
503 503
                 set_post_thumbnail( $post_id, $media_id );
504 504
             }
505 505
 
506
-        } elseif ( !empty( $_POST[ $input_name ] ) && is_array( $value ) ) {
506
+        } elseif ( ! empty( $_POST[ $input_name ] ) && is_array( $value ) ) {
507 507
 
508 508
             // Same image although the image title, caption or description might have changed
509 509
 
510 510
             $ary = array();
511
-            if( ! empty( $entry[ $field_id ] ) ) {
511
+            if ( ! empty( $entry[ $field_id ] ) ) {
512 512
                 $ary = is_array( $entry[ $field_id ] ) ? $entry[ $field_id ] : explode( '|:|', $entry[ $field_id ] );
513 513
             }
514 514
             $img_url = rgar( $ary, 0 );
515 515
 
516 516
             // is this really the same image or something went wrong ?
517
-            if( $img_url === $_POST[ $input_name ] ) {
517
+            if ( $img_url === $_POST[ $input_name ] ) {
518 518
 
519
-                $img_title       = rgar( $value, $field_id .'.1' );
520
-                $img_caption     = rgar( $value, $field_id .'.4' );
521
-                $img_description = rgar( $value, $field_id .'.7' );
519
+                $img_title       = rgar( $value, $field_id . '.1' );
520
+                $img_caption     = rgar( $value, $field_id . '.4' );
521
+                $img_description = rgar( $value, $field_id . '.7' );
522 522
 
523 523
                 $value = ! empty( $img_url ) ? $img_url . "|:|" . $img_title . "|:|" . $img_caption . "|:|" . $img_description : '';
524 524
 
@@ -558,11 +558,11 @@  discard block
 block discarded – undo
558 558
      */
559 559
     private function maybe_update_post_fields( $form ) {
560 560
 
561
-        $post_id = $this->entry['post_id'];
561
+        $post_id = $this->entry[ 'post_id' ];
562 562
 
563 563
         // Security check
564
-        if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) {
565
-            do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id );
564
+        if ( false === GVCommon::has_cap( 'edit_post', $post_id ) ) {
565
+            do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #' . $post_id );
566 566
             return;
567 567
         }
568 568
 
@@ -574,25 +574,25 @@  discard block
 block discarded – undo
574 574
 
575 575
             $field = RGFormsModel::get_field( $form, $field_id );
576 576
 
577
-            if( ! $field ) {
577
+            if ( ! $field ) {
578 578
                 continue;
579 579
             }
580 580
 
581
-            if( GFCommon::is_post_field( $field ) && 'post_category' !== $field->type ) {
581
+            if ( GFCommon::is_post_field( $field ) && 'post_category' !== $field->type ) {
582 582
 
583 583
                 // Get the value of the field, including $_POSTed value
584 584
                 $value = RGFormsModel::get_field_value( $field );
585 585
 
586 586
                 // Use temporary entry variable, to make values available to fill_post_template() and update_post_image()
587 587
                 $entry_tmp = $this->entry;
588
-                $entry_tmp["{$field_id}"] = $value;
588
+                $entry_tmp[ "{$field_id}" ] = $value;
589 589
 
590
-                switch( $field->type ) {
590
+                switch ( $field->type ) {
591 591
 
592 592
                     case 'post_title':
593 593
                         $post_title = $value;
594
-                        if( rgar( $form, 'postTitleTemplateEnabled' ) ) {
595
-                            $post_title = $this->fill_post_template( $form['postTitleTemplate'], $form, $entry_tmp );
594
+                        if ( rgar( $form, 'postTitleTemplateEnabled' ) ) {
595
+                            $post_title = $this->fill_post_template( $form[ 'postTitleTemplate' ], $form, $entry_tmp );
596 596
                         }
597 597
                         $updated_post->post_title = $post_title;
598 598
                         $updated_post->post_name  = $post_title;
@@ -601,8 +601,8 @@  discard block
 block discarded – undo
601 601
 
602 602
                     case 'post_content':
603 603
                         $post_content = $value;
604
-                        if( rgar( $form, 'postContentTemplateEnabled' ) ) {
605
-                            $post_content = $this->fill_post_template( $form['postContentTemplate'], $form, $entry_tmp, true );
604
+                        if ( rgar( $form, 'postContentTemplateEnabled' ) ) {
605
+                            $post_content = $this->fill_post_template( $form[ 'postContentTemplate' ], $form, $entry_tmp, true );
606 606
                         }
607 607
                         $updated_post->post_content = $post_content;
608 608
                         unset( $post_content );
@@ -616,19 +616,19 @@  discard block
 block discarded – undo
616 616
                     case 'post_category':
617 617
                         break;
618 618
                     case 'post_custom_field':
619
-                        if( ! empty( $field->customFieldTemplateEnabled ) ) {
619
+                        if ( ! empty( $field->customFieldTemplateEnabled ) ) {
620 620
                             $value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true );
621 621
                         }
622 622
 
623 623
                         $input_type = RGFormsModel::get_input_type( $field );
624 624
 
625 625
                         // Only certain custom field types are supported
626
-                        switch( $input_type ) {
626
+                        switch ( $input_type ) {
627 627
                             case 'fileupload':
628 628
                             case 'list':
629 629
                             case 'multiselect':
630
-                                if( ! is_string( $value ) ) {
631
-                                    $value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value );
630
+                                if ( ! is_string( $value ) ) {
631
+                                    $value = function_exists( 'wp_json_encode' ) ? wp_json_encode( $value ) : json_encode( $value );
632 632
                                 }
633 633
                             // break; left intentionally out
634 634
                             default:
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
                 }
645 645
 
646 646
                 // update entry after
647
-                $this->entry["{$field_id}"] = $value;
647
+                $this->entry[ "{$field_id}" ] = $value;
648 648
 
649 649
                 $update_entry = true;
650 650
 
@@ -653,25 +653,25 @@  discard block
 block discarded – undo
653 653
 
654 654
         }
655 655
 
656
-        if( $update_entry ) {
656
+        if ( $update_entry ) {
657 657
 
658 658
             $return_entry = GFAPI::update_entry( $this->entry );
659 659
 
660
-            if( is_wp_error( $return_entry ) ) {
660
+            if ( is_wp_error( $return_entry ) ) {
661 661
                do_action( 'gravityview_log_error', 'Updating the entry post fields failed', array( '$this->entry' => $this->entry, '$return_entry' => $return_entry ) );
662 662
             } else {
663
-                do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' );
663
+                do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #' . $post_id . ' succeeded' );
664 664
             }
665 665
 
666 666
         }
667 667
 
668 668
         $return_post = wp_update_post( $updated_post, true );
669 669
 
670
-        if( is_wp_error( $return_post ) ) {
670
+        if ( is_wp_error( $return_post ) ) {
671 671
             $return_post->add_data( $updated_post, '$updated_post' );
672 672
             do_action( 'gravityview_log_error', 'Updating the post content failed', compact( 'updated_post', 'return_post' ) );
673 673
         } else {
674
-            do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post );
674
+            do_action( 'gravityview_log_debug', 'Updating the post content for post #' . $post_id . ' succeeded', $updated_post );
675 675
         }
676 676
     }
677 677
 
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
         $output = GFCommon::replace_variables( $output, $form, $entry, false, false, false );
702 702
 
703 703
         // replace conditional shortcodes
704
-        if( $do_shortcode ) {
704
+        if ( $do_shortcode ) {
705 705
             $output = do_shortcode( $output );
706 706
         }
707 707
 
@@ -720,18 +720,18 @@  discard block
 block discarded – undo
720 720
      */
721 721
     function after_update() {
722 722
 
723
-        do_action( 'gform_after_update_entry', $this->form, $this->entry['id'], self::$original_entry );
724
-        do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] );
723
+        do_action( 'gform_after_update_entry', $this->form, $this->entry[ 'id' ], self::$original_entry );
724
+        do_action( "gform_after_update_entry_{$this->form[ 'id' ]}", $this->form, $this->entry[ 'id' ] );
725 725
 
726 726
         // Re-define the entry now that we've updated it.
727
-        $entry = RGFormsModel::get_lead( $this->entry['id'] );
727
+        $entry = RGFormsModel::get_lead( $this->entry[ 'id' ] );
728 728
 
729 729
         $entry = GFFormsModel::set_entry_meta( $entry, $this->form );
730 730
 
731 731
         // We need to clear the cache because Gravity Forms caches the field values, which
732 732
         // we have just updated.
733
-        foreach ($this->form['fields'] as $key => $field) {
734
-            GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id );
733
+        foreach ( $this->form[ 'fields' ] as $key => $field ) {
734
+            GFFormsModel::refresh_lead_field_value( $entry[ 'id' ], $field->id );
735 735
         }
736 736
 
737 737
         $this->entry = $entry;
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
 
750 750
         <div class="gv-edit-entry-wrapper"><?php
751 751
 
752
-            $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this );
752
+            $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file . '/partials/inline-javascript.php', $this );
753 753
 
754 754
             /**
755 755
              * Fixes weird wpautop() issue
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
                      * @param string $edit_entry_title Modify the "Edit Entry" title
766 766
                      * @param GravityView_Edit_Entry_Render $this This object
767 767
                      */
768
-                    $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this );
768
+                    $edit_entry_title = apply_filters( 'gravityview_edit_entry_title', __( 'Edit Entry', 'gravityview' ), $this );
769 769
 
770 770
                     echo esc_attr( $edit_entry_title );
771 771
             ?></span>
@@ -805,20 +805,20 @@  discard block
 block discarded – undo
805 805
      */
806 806
     private function maybe_print_message() {
807 807
 
808
-        if( rgpost('action') === 'update' ) {
808
+        if ( rgpost( 'action' ) === 'update' ) {
809 809
 
810 810
             $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) );
811 811
 
812
-            if( ! $this->is_valid ){
812
+            if ( ! $this->is_valid ) {
813 813
 
814 814
                 // Keeping this compatible with Gravity Forms.
815
-                $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>";
816
-                $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form);
815
+                $validation_message = "<div class='validation_error'>" . __( 'There was a problem with your submission.', 'gravityview' ) . " " . __( 'Errors have been highlighted below.', 'gravityview' ) . "</div>";
816
+                $message = apply_filters( "gform_validation_message_{$this->form[ 'id' ]}", apply_filters( "gform_validation_message", $validation_message, $this->form ), $this->form );
817 817
 
818
-                echo GVCommon::generate_notice( $message , 'gv-error' );
818
+                echo GVCommon::generate_notice( $message, 'gv-error' );
819 819
 
820 820
             } else {
821
-                $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' );
821
+                $entry_updated_message = sprintf( esc_attr__( 'Entry Updated. %sReturn to Entry%s', 'gravityview' ), '<a href="' . $back_link . '">', '</a>' );
822 822
 
823 823
                 /**
824 824
                  * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link)
@@ -828,7 +828,7 @@  discard block
 block discarded – undo
828 828
                  * @param array $entry Gravity Forms entry array
829 829
                  * @param string $back_link URL to return to the original entry. @since 1.6
830 830
                  */
831
-                $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link );
831
+                $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message, $this->view_id, $this->entry, $back_link );
832 832
 
833 833
                 echo GVCommon::generate_notice( $message );
834 834
             }
@@ -852,24 +852,24 @@  discard block
 block discarded – undo
852 852
          */
853 853
         do_action( 'gravityview/edit-entry/render/before', $this );
854 854
 
855
-        add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 );
856
-        add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') );
855
+        add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000, 3 );
856
+        add_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) );
857 857
         add_filter( 'gform_disable_view_counter', '__return_true' );
858 858
 
859 859
         add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 );
860 860
         add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 );
861 861
 
862
-        add_filter( 'gform_field_value', array( $this, 'fix_survey_fields_value'), 10, 3 );
862
+        add_filter( 'gform_field_value', array( $this, 'fix_survey_fields_value' ), 10, 3 );
863 863
 
864 864
         // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin.
865
-        unset( $_GET['page'] );
865
+        unset( $_GET[ 'page' ] );
866 866
 
867 867
         // TODO: Verify multiple-page forms
868 868
         // TODO: Product fields are not editable
869 869
 
870
-        $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry );
870
+        $html = GFFormDisplay::get_form( $this->form[ 'id' ], false, false, true, $this->entry );
871 871
 
872
-        remove_filter( 'gform_field_value', array( $this, 'fix_survey_fields_value'), 10 );
872
+        remove_filter( 'gform_field_value', array( $this, 'fix_survey_fields_value' ), 10 );
873 873
 	    remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 );
874 874
         remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) );
875 875
         remove_filter( 'gform_disable_view_counter', '__return_true' );
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
      */
903 903
     function fix_survey_fields_value( $value, $field, $name ) {
904 904
         
905
-        if( 'survey' === $field->type ) {
905
+        if ( 'survey' === $field->type ) {
906 906
 
907 907
 	        // We need to run through each survey row until we find a match for expected values
908 908
 	        foreach ( $this->entry as $field_id => $field_value ) {
@@ -911,11 +911,11 @@  discard block
 block discarded – undo
911 911
 			        continue;
912 912
 		        }
913 913
 
914
-		        if( rgar( $field, 'gsurveyLikertEnableMultipleRows' ) ) {
914
+		        if ( rgar( $field, 'gsurveyLikertEnableMultipleRows' ) ) {
915 915
 			        list( $row_val, $col_val ) = explode( ':', $field_value, 2 );
916 916
 
917 917
 		            // If the $name matches the $row_val, we are processing the correct row
918
-			        if( $row_val === $name ) {
918
+			        if ( $row_val === $name ) {
919 919
 				        $value = $field_value;
920 920
 				        break;
921 921
 			        }
@@ -936,7 +936,7 @@  discard block
 block discarded – undo
936 936
      * @return string
937 937
      */
938 938
     public function render_form_buttons() {
939
-        return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this );
939
+        return gravityview_ob_include( GravityView_Edit_Entry::$file . '/partials/form-buttons.php', $this );
940 940
     }
941 941
 
942 942
 
@@ -956,17 +956,17 @@  discard block
 block discarded – undo
956 956
     public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) {
957 957
 
958 958
         // In case we have validated the form, use it to inject the validation results into the form render
959
-        if( isset( $this->form_after_validation ) ) {
959
+        if ( isset( $this->form_after_validation ) ) {
960 960
             $form = $this->form_after_validation;
961 961
         } else {
962
-            $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id );
962
+            $form[ 'fields' ] = $this->get_configured_edit_fields( $form, $this->view_id );
963 963
         }
964 964
 
965 965
         $form = $this->filter_conditional_logic( $form );
966 966
 
967 967
         // for now we don't support Save and Continue feature.
968
-        if( ! self::$supports_save_and_continue ) {
969
-	        unset( $form['save'] );
968
+        if ( ! self::$supports_save_and_continue ) {
969
+	        unset( $form[ 'save' ] );
970 970
         }
971 971
 
972 972
         return $form;
@@ -987,29 +987,29 @@  discard block
 block discarded – undo
987 987
      */
988 988
     function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) {
989 989
 
990
-        if( GFCommon::is_post_field( $field ) ) {
990
+        if ( GFCommon::is_post_field( $field ) ) {
991 991
 
992 992
             $message = null;
993 993
 
994 994
             // First, make sure they have the capability to edit the post.
995
-            if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) {
995
+            if ( false === current_user_can( 'edit_post', $this->entry[ 'post_id' ] ) ) {
996 996
 
997 997
                 /**
998 998
                  * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post
999 999
                  * @param string $message The existing "You don't have permission..." text
1000 1000
                  */
1001
-                $message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don&rsquo;t have permission to edit this post.', 'gravityview') );
1001
+                $message = apply_filters( 'gravityview/edit_entry/unsupported_post_field_text', __( 'You don&rsquo;t have permission to edit this post.', 'gravityview' ) );
1002 1002
 
1003
-            } elseif( null === get_post( $this->entry['post_id'] ) ) {
1003
+            } elseif ( null === get_post( $this->entry[ 'post_id' ] ) ) {
1004 1004
                 /**
1005 1005
                  * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists
1006 1006
                  * @param string $message The existing "This field is not editable; the post no longer exists." text
1007 1007
                  */
1008
-                $message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) );
1008
+                $message = apply_filters( 'gravityview/edit_entry/no_post_text', __( 'This field is not editable; the post no longer exists.', 'gravityview' ) );
1009 1009
             }
1010 1010
 
1011
-            if( $message ) {
1012
-                $field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) );
1011
+            if ( $message ) {
1012
+                $field_content = sprintf( '<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) );
1013 1013
             }
1014 1014
         }
1015 1015
 
@@ -1034,8 +1034,8 @@  discard block
 block discarded – undo
1034 1034
 
1035 1035
         // If the form has been submitted, then we don't need to pre-fill the values,
1036 1036
         // Except for fileupload type and when a field input is overridden- run always!!
1037
-        if(
1038
-            ( $this->is_edit_entry_submission() && !in_array( $field->type, array( 'fileupload', 'post_image' ) ) )
1037
+        if (
1038
+            ( $this->is_edit_entry_submission() && ! in_array( $field->type, array( 'fileupload', 'post_image' ) ) )
1039 1039
             && false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) )
1040 1040
             || ! empty( $field_content )
1041 1041
             || in_array( $field->type, array( 'honeypot' ) )
@@ -1045,8 +1045,8 @@  discard block
 block discarded – undo
1045 1045
         }
1046 1046
 
1047 1047
         // Turn on Admin-style display for file upload fields only
1048
-        if( 'fileupload' === $field->type ) {
1049
-            $_GET['page'] = 'gf_entries';
1048
+        if ( 'fileupload' === $field->type ) {
1049
+            $_GET[ 'page' ] = 'gf_entries';
1050 1050
         }
1051 1051
 
1052 1052
         // SET SOME FIELD DEFAULTS TO PREVENT ISSUES
@@ -1073,12 +1073,12 @@  discard block
 block discarded – undo
1073 1073
          * @param mixed $field_value field value used to populate the input
1074 1074
          * @param GF_Field $field Gravity Forms field object
1075 1075
          */
1076
-        $field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type , $field_value, $field );
1076
+        $field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type, $field_value, $field );
1077 1077
 
1078 1078
 	    // Prevent any PHP warnings, like undefined index
1079 1079
 	    ob_start();
1080 1080
 
1081
-        if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) {
1081
+        if ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) {
1082 1082
             /** @var GF_Field $gv_field */
1083 1083
             $return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field );
1084 1084
         } else {
@@ -1089,7 +1089,7 @@  discard block
 block discarded – undo
1089 1089
 	    // If there was output, it's an error
1090 1090
 	    $warnings = ob_get_clean();
1091 1091
 
1092
-	    if( !empty( $warnings ) ) {
1092
+	    if ( ! empty( $warnings ) ) {
1093 1093
 		    do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value );
1094 1094
 	    }
1095 1095
 
@@ -1098,7 +1098,7 @@  discard block
 block discarded – undo
1098 1098
          * We need the fileupload html field to render with the proper id
1099 1099
          *  ( <li id="field_80_16" ... > )
1100 1100
          */
1101
-        unset( $_GET['page'] );
1101
+        unset( $_GET[ 'page' ] );
1102 1102
 
1103 1103
         return $return;
1104 1104
     }
@@ -1121,7 +1121,7 @@  discard block
 block discarded – undo
1121 1121
         $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field );
1122 1122
 
1123 1123
         // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs)
1124
-        if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) {
1124
+        if ( isset( $field->inputs ) && is_array( $field->inputs ) && ! in_array( $field->type, array( 'time', 'date' ) ) ) {
1125 1125
 
1126 1126
             $field_value = array();
1127 1127
 
@@ -1130,10 +1130,10 @@  discard block
 block discarded – undo
1130 1130
 
1131 1131
             foreach ( (array)$field->inputs as $input ) {
1132 1132
 
1133
-                $input_id = strval( $input['id'] );
1133
+                $input_id = strval( $input[ 'id' ] );
1134 1134
                 
1135 1135
                 if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) {
1136
-                    $field_value[ $input_id ] =  'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ];
1136
+                    $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ];
1137 1137
                     $allow_pre_populated = false;
1138 1138
                 }
1139 1139
 
@@ -1141,7 +1141,7 @@  discard block
 block discarded – undo
1141 1141
 
1142 1142
             $pre_value = $field->get_value_submission( array(), false );
1143 1143
 
1144
-            $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value;
1144
+            $field_value = ! $allow_pre_populated && ! ( $override_saved_value && ! gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value;
1145 1145
 
1146 1146
         } else {
1147 1147
 
@@ -1152,13 +1152,13 @@  discard block
 block discarded – undo
1152 1152
 
1153 1153
             // saved field entry value (if empty, fallback to the pre-populated value, if exists)
1154 1154
             // or pre-populated value if not empty and set to override saved value
1155
-            $field_value = !gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value;
1155
+            $field_value = ! gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && ! gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value;
1156 1156
 
1157 1157
             // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs.
1158
-            if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) {
1158
+            if ( 'post_category' === $field->type && ! gv_empty( $field_value, false, false ) ) {
1159 1159
                 $categories = array();
1160 1160
                 foreach ( explode( ',', $field_value ) as $cat_string ) {
1161
-                    $categories[] = GFCommon::format_post_category( $cat_string, true );
1161
+                    $categories[ ] = GFCommon::format_post_category( $cat_string, true );
1162 1162
                 }
1163 1163
                 $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories );
1164 1164
             }
@@ -1183,12 +1183,12 @@  discard block
 block discarded – undo
1183 1183
      */
1184 1184
     function gform_pre_validation( $form ) {
1185 1185
 
1186
-        if( ! $this->verify_nonce() ) {
1186
+        if ( ! $this->verify_nonce() ) {
1187 1187
             return $form;
1188 1188
         }
1189 1189
 
1190 1190
         // Fix PHP warning regarding undefined index.
1191
-        foreach ( $form['fields'] as &$field) {
1191
+        foreach ( $form[ 'fields' ] as &$field ) {
1192 1192
 
1193 1193
             // This is because we're doing admin form pretending to be front-end, so Gravity Forms
1194 1194
             // expects certain field array items to be set.
@@ -1201,7 +1201,7 @@  discard block
 block discarded – undo
1201 1201
                 $field['emailConfirmEnabled'] = '';
1202 1202
             }*/
1203 1203
 
1204
-            switch( RGFormsModel::get_input_type( $field ) ) {
1204
+            switch ( RGFormsModel::get_input_type( $field ) ) {
1205 1205
 
1206 1206
                 /**
1207 1207
                  * 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.
@@ -1215,37 +1215,37 @@  discard block
 block discarded – undo
1215 1215
                     // Set the previous value
1216 1216
                     $entry = $this->get_entry();
1217 1217
 
1218
-                    $input_name = 'input_'.$field->id;
1219
-                    $form_id = $form['id'];
1218
+                    $input_name = 'input_' . $field->id;
1219
+                    $form_id = $form[ 'id' ];
1220 1220
 
1221 1221
                     $value = NULL;
1222 1222
 
1223 1223
                     // Use the previous entry value as the default.
1224
-                    if( isset( $entry[ $field->id ] ) ) {
1224
+                    if ( isset( $entry[ $field->id ] ) ) {
1225 1225
                         $value = $entry[ $field->id ];
1226 1226
                     }
1227 1227
 
1228 1228
                     // If this is a single upload file
1229
-                    if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) {
1230
-                        $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] );
1231
-                        $value = $file_path['url'];
1229
+                    if ( ! empty( $_FILES[ $input_name ] ) && ! empty( $_FILES[ $input_name ][ 'name' ] ) ) {
1230
+                        $file_path = GFFormsModel::get_file_upload_path( $form[ 'id' ], $_FILES[ $input_name ][ 'name' ] );
1231
+                        $value = $file_path[ 'url' ];
1232 1232
 
1233 1233
                     } else {
1234 1234
 
1235 1235
                         // Fix PHP warning on line 1498 of form_display.php for post_image fields
1236 1236
                         // Fix PHP Notice:  Undefined index:  size in form_display.php on line 1511
1237
-                        $_FILES[ $input_name ] = array('name' => '', 'size' => '' );
1237
+                        $_FILES[ $input_name ] = array( 'name' => '', 'size' => '' );
1238 1238
 
1239 1239
                     }
1240 1240
 
1241
-                    if( rgar($field, "multipleFiles") ) {
1241
+                    if ( rgar( $field, "multipleFiles" ) ) {
1242 1242
 
1243 1243
                         // If there are fresh uploads, process and merge them.
1244 1244
                         // Otherwise, use the passed values, which should be json-encoded array of URLs
1245
-                        if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) {
1245
+                        if ( isset( GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] ) ) {
1246 1246
                             $value = empty( $value ) ? '[]' : $value;
1247 1247
                             $value = stripslashes_deep( $value );
1248
-                            $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array());
1248
+                            $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry[ 'id' ], array() );
1249 1249
                         }
1250 1250
 
1251 1251
                     } else {
@@ -1263,14 +1263,14 @@  discard block
 block discarded – undo
1263 1263
 
1264 1264
                 case 'number':
1265 1265
                     // Fix "undefined index" issue at line 1286 in form_display.php
1266
-                    if( !isset( $_POST['input_'.$field->id ] ) ) {
1267
-                        $_POST['input_'.$field->id ] = NULL;
1266
+                    if ( ! isset( $_POST[ 'input_' . $field->id ] ) ) {
1267
+                        $_POST[ 'input_' . $field->id ] = NULL;
1268 1268
                     }
1269 1269
                     break;
1270 1270
                 case 'captcha':
1271 1271
                     // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php
1272
-                    $_POST['recaptcha_challenge_field'] = NULL;
1273
-                    $_POST['recaptcha_response_field'] = NULL;
1272
+                    $_POST[ 'recaptcha_challenge_field' ] = NULL;
1273
+                    $_POST[ 'recaptcha_response_field' ] = NULL;
1274 1274
                     break;
1275 1275
             }
1276 1276
 
@@ -1306,7 +1306,7 @@  discard block
 block discarded – undo
1306 1306
          * You can enter whatever you want!
1307 1307
          * We try validating, and customize the results using `self::custom_validation()`
1308 1308
          */
1309
-        add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4);
1309
+        add_filter( 'gform_validation_' . $this->form_id, array( $this, 'custom_validation' ), 10, 4 );
1310 1310
 
1311 1311
         // Needed by the validate funtion
1312 1312
         $failed_validation_page = NULL;
@@ -1314,14 +1314,14 @@  discard block
 block discarded – undo
1314 1314
 
1315 1315
         // Prevent entry limit from running when editing an entry, also
1316 1316
         // prevent form scheduling from preventing editing
1317
-        unset( $this->form['limitEntries'], $this->form['scheduleForm'] );
1317
+        unset( $this->form[ 'limitEntries' ], $this->form[ 'scheduleForm' ] );
1318 1318
 
1319 1319
         // Hide fields depending on Edit Entry settings
1320
-        $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id );
1320
+        $this->form[ 'fields' ] = $this->get_configured_edit_fields( $this->form, $this->view_id );
1321 1321
 
1322 1322
         $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page );
1323 1323
 
1324
-        remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 );
1324
+        remove_filter( 'gform_validation_' . $this->form_id, array( $this, 'custom_validation' ), 10 );
1325 1325
     }
1326 1326
 
1327 1327
 
@@ -1338,13 +1338,13 @@  discard block
 block discarded – undo
1338 1338
      */
1339 1339
     function custom_validation( $validation_results ) {
1340 1340
 
1341
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results );
1341
+        do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results );
1342 1342
 
1343
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
1343
+        do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
1344 1344
 
1345 1345
         $gv_valid = true;
1346 1346
 
1347
-        foreach ( $validation_results['form']['fields'] as $key => &$field ) {
1347
+        foreach ( $validation_results[ 'form' ][ 'fields' ] as $key => &$field ) {
1348 1348
 
1349 1349
             $value = RGFormsModel::get_field_value( $field );
1350 1350
             $field_type = RGFormsModel::get_input_type( $field );
@@ -1357,35 +1357,35 @@  discard block
 block discarded – undo
1357 1357
                 case 'post_image':
1358 1358
 
1359 1359
                     // in case nothing is uploaded but there are already files saved
1360
-                    if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) {
1360
+                    if ( ! empty( $field->failed_validation ) && ! empty( $field->isRequired ) && ! empty( $value ) ) {
1361 1361
                         $field->failed_validation = false;
1362 1362
                         unset( $field->validation_message );
1363 1363
                     }
1364 1364
 
1365 1365
                     // validate if multi file upload reached max number of files [maxFiles] => 2
1366
-                    if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) {
1366
+                    if ( rgobj( $field, 'maxFiles' ) && rgobj( $field, 'multipleFiles' ) ) {
1367 1367
 
1368 1368
                         $input_name = 'input_' . $field->id;
1369 1369
                         //uploaded
1370
-                        $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array();
1370
+                        $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results[ 'form' ][ 'id' ] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results[ 'form' ][ 'id' ] ][ $input_name ] : array();
1371 1371
 
1372 1372
                         //existent
1373 1373
                         $entry = $this->get_entry();
1374 1374
                         $value = NULL;
1375
-                        if( isset( $entry[ $field->id ] ) ) {
1375
+                        if ( isset( $entry[ $field->id ] ) ) {
1376 1376
                             $value = json_decode( $entry[ $field->id ], true );
1377 1377
                         }
1378 1378
 
1379 1379
                         // count uploaded files and existent entry files
1380 1380
                         $count_files = count( $file_names ) + count( $value );
1381 1381
 
1382
-                        if( $count_files > $field->maxFiles ) {
1382
+                        if ( $count_files > $field->maxFiles ) {
1383 1383
                             $field->validation_message = __( 'Maximum number of files reached', 'gravityview' );
1384 1384
                             $field->failed_validation = 1;
1385 1385
                             $gv_valid = false;
1386 1386
 
1387 1387
                             // in case of error make sure the newest upload files are removed from the upload input
1388
-                            GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null;
1388
+                            GFFormsModel::$uploaded_files[ $validation_results[ 'form' ][ 'id' ] ] = null;
1389 1389
                         }
1390 1390
 
1391 1391
                     }
@@ -1396,7 +1396,7 @@  discard block
 block discarded – undo
1396 1396
             }
1397 1397
 
1398 1398
             // This field has failed validation.
1399
-            if( !empty( $field->failed_validation ) ) {
1399
+            if ( ! empty( $field->failed_validation ) ) {
1400 1400
 
1401 1401
                 do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) );
1402 1402
 
@@ -1414,32 +1414,32 @@  discard block
 block discarded – undo
1414 1414
                 }
1415 1415
 
1416 1416
                 // You can't continue inside a switch, so we do it after.
1417
-                if( empty( $field->failed_validation ) ) {
1417
+                if ( empty( $field->failed_validation ) ) {
1418 1418
                     continue;
1419 1419
                 }
1420 1420
 
1421 1421
                 // checks if the No Duplicates option is not validating entry against itself, since
1422 1422
                 // we're editing a stored entry, it would also assume it's a duplicate.
1423
-                if( !empty( $field->noDuplicates ) ) {
1423
+                if ( ! empty( $field->noDuplicates ) ) {
1424 1424
 
1425 1425
                     $entry = $this->get_entry();
1426 1426
 
1427 1427
                     // If the value of the entry is the same as the stored value
1428 1428
                     // Then we can assume it's not a duplicate, it's the same.
1429
-                    if( !empty( $entry ) && $value == $entry[ $field->id ] ) {
1429
+                    if ( ! empty( $entry ) && $value == $entry[ $field->id ] ) {
1430 1430
                         //if value submitted was not changed, then don't validate
1431 1431
                         $field->failed_validation = false;
1432 1432
 
1433 1433
                         unset( $field->validation_message );
1434 1434
 
1435
-                        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry );
1435
+                        do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry );
1436 1436
 
1437 1437
                         continue;
1438 1438
                     }
1439 1439
                 }
1440 1440
 
1441 1441
                 // if here then probably we are facing the validation 'At least one field must be filled out'
1442
-                if( GFFormDisplay::is_empty( $field, $this->form_id  ) && empty( $field->isRequired ) ) {
1442
+                if ( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) {
1443 1443
                     unset( $field->validation_message );
1444 1444
 	                $field->validation_message = false;
1445 1445
                     continue;
@@ -1451,12 +1451,12 @@  discard block
 block discarded – undo
1451 1451
 
1452 1452
         }
1453 1453
 
1454
-        $validation_results['is_valid'] = $gv_valid;
1454
+        $validation_results[ 'is_valid' ] = $gv_valid;
1455 1455
 
1456
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results );
1456
+        do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results );
1457 1457
 
1458 1458
         // We'll need this result when rendering the form ( on GFFormDisplay::get_form )
1459
-        $this->form_after_validation = $validation_results['form'];
1459
+        $this->form_after_validation = $validation_results[ 'form' ];
1460 1460
 
1461 1461
         return $validation_results;
1462 1462
     }
@@ -1469,7 +1469,7 @@  discard block
 block discarded – undo
1469 1469
      */
1470 1470
     public function get_entry() {
1471 1471
 
1472
-        if( empty( $this->entry ) ) {
1472
+        if ( empty( $this->entry ) ) {
1473 1473
             // Get the database value of the entry that's being edited
1474 1474
             $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() );
1475 1475
         }
@@ -1496,13 +1496,13 @@  discard block
 block discarded – undo
1496 1496
         $properties = GravityView_View_Data::getInstance()->get_fields( $view_id );
1497 1497
 
1498 1498
         // If edit tab not yet configured, show all fields
1499
-        $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL;
1499
+        $edit_fields = ! empty( $properties[ 'edit_edit-fields' ] ) ? $properties[ 'edit_edit-fields' ] : NULL;
1500 1500
 
1501 1501
         // Show hidden fields as text fields
1502 1502
         $form = $this->fix_survey_fields( $form );
1503 1503
 
1504 1504
         // Hide fields depending on admin settings
1505
-        $fields = $this->filter_fields( $form['fields'], $edit_fields );
1505
+        $fields = $this->filter_fields( $form[ 'fields' ], $edit_fields );
1506 1506
 
1507 1507
 	    // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't.
1508 1508
 	    $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id );
@@ -1532,7 +1532,7 @@  discard block
 block discarded – undo
1532 1532
     private function fix_survey_fields( $form ) {
1533 1533
 
1534 1534
         /** @var GF_Field $field */
1535
-        foreach( $form['fields'] as &$field ) {
1535
+        foreach ( $form[ 'fields' ] as &$field ) {
1536 1536
             $field->allowsPrepopulate = true;
1537 1537
         }
1538 1538
 
@@ -1553,7 +1553,7 @@  discard block
 block discarded – undo
1553 1553
      */
1554 1554
     private function filter_fields( $fields, $configured_fields ) {
1555 1555
 
1556
-        if( empty( $fields ) || !is_array( $fields ) ) {
1556
+        if ( empty( $fields ) || ! is_array( $fields ) ) {
1557 1557
             return $fields;
1558 1558
         }
1559 1559
 
@@ -1570,13 +1570,13 @@  discard block
 block discarded – undo
1570 1570
 	     */
1571 1571
 	    $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) );
1572 1572
 
1573
-	    if( $hide_product_fields ) {
1574
-		    $field_type_blacklist[] = 'option';
1575
-		    $field_type_blacklist[] = 'quantity';
1576
-            $field_type_blacklist[] = 'product';
1577
-            $field_type_blacklist[] = 'total';
1578
-            $field_type_blacklist[] = 'shipping';
1579
-            $field_type_blacklist[] = 'calculation';
1573
+	    if ( $hide_product_fields ) {
1574
+		    $field_type_blacklist[ ] = 'option';
1575
+		    $field_type_blacklist[ ] = 'quantity';
1576
+            $field_type_blacklist[ ] = 'product';
1577
+            $field_type_blacklist[ ] = 'total';
1578
+            $field_type_blacklist[ ] = 'shipping';
1579
+            $field_type_blacklist[ ] = 'calculation';
1580 1580
 	    }
1581 1581
 
1582 1582
         // First, remove blacklist or calculation fields
@@ -1584,24 +1584,24 @@  discard block
 block discarded – undo
1584 1584
 
1585 1585
             // Remove the fields that have calculation properties and keep them to be used later
1586 1586
             // @since 1.16.2
1587
-            if( $field->has_calculation() ) {
1588
-                $this->fields_with_calculation[] = $field;
1587
+            if ( $field->has_calculation() ) {
1588
+                $this->fields_with_calculation[ ] = $field;
1589 1589
                 // don't remove the calculation fields on form render.
1590 1590
             }
1591 1591
 
1592 1592
             // process total field after all fields have been saved
1593 1593
             if ( $field->type == 'total' ) {
1594
-                $this->total_fields[] = $field;
1594
+                $this->total_fields[ ] = $field;
1595 1595
                 unset( $fields[ $key ] );
1596 1596
             }
1597 1597
 
1598
-            if( in_array( $field->type, $field_type_blacklist ) ) {
1598
+            if ( in_array( $field->type, $field_type_blacklist ) ) {
1599 1599
                 unset( $fields[ $key ] );
1600 1600
             }
1601 1601
         }
1602 1602
 
1603 1603
         // The Edit tab has not been configured, so we return all fields by default.
1604
-        if( empty( $configured_fields ) ) {
1604
+        if ( empty( $configured_fields ) ) {
1605 1605
             return $fields;
1606 1606
         }
1607 1607
 
@@ -1611,8 +1611,8 @@  discard block
 block discarded – undo
1611 1611
 	        /** @var GF_Field $field */
1612 1612
 	        foreach ( $fields as $field ) {
1613 1613
 
1614
-                if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) {
1615
-                    $edit_fields[] = $this->merge_field_properties( $field, $configured_field );
1614
+                if ( intval( $configured_field[ 'id' ] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) {
1615
+                    $edit_fields[ ] = $this->merge_field_properties( $field, $configured_field );
1616 1616
                     break;
1617 1617
                 }
1618 1618
 
@@ -1635,14 +1635,14 @@  discard block
 block discarded – undo
1635 1635
 
1636 1636
         $return_field = $field;
1637 1637
 
1638
-        if( empty( $field_setting['show_label'] ) ) {
1638
+        if ( empty( $field_setting[ 'show_label' ] ) ) {
1639 1639
             $return_field->label = '';
1640
-        } elseif ( !empty( $field_setting['custom_label'] ) ) {
1641
-            $return_field->label = $field_setting['custom_label'];
1640
+        } elseif ( ! empty( $field_setting[ 'custom_label' ] ) ) {
1641
+            $return_field->label = $field_setting[ 'custom_label' ];
1642 1642
         }
1643 1643
 
1644
-        if( !empty( $field_setting['custom_class'] ) ) {
1645
-            $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] );
1644
+        if ( ! empty( $field_setting[ 'custom_class' ] ) ) {
1645
+            $return_field->cssClass .= ' ' . gravityview_sanitize_html_class( $field_setting[ 'custom_class' ] );
1646 1646
         }
1647 1647
 
1648 1648
         /**
@@ -1680,16 +1680,16 @@  discard block
 block discarded – undo
1680 1680
 	     */
1681 1681
 	    $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id );
1682 1682
 
1683
-	    if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) {
1684
-            foreach( $fields as $k => $field ) {
1685
-                if( $field->adminOnly ) {
1683
+	    if ( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry[ 'id' ] ) ) {
1684
+            foreach ( $fields as $k => $field ) {
1685
+                if ( $field->adminOnly ) {
1686 1686
                     unset( $fields[ $k ] );
1687 1687
                 }
1688 1688
             }
1689 1689
             return $fields;
1690 1690
         }
1691 1691
 
1692
-	    foreach( $fields as &$field ) {
1692
+	    foreach ( $fields as &$field ) {
1693 1693
 		    $field->adminOnly = false;
1694 1694
         }
1695 1695
 
@@ -1716,16 +1716,16 @@  discard block
 block discarded – undo
1716 1716
          */
1717 1717
         $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form );
1718 1718
 
1719
-        if( $use_conditional_logic ) {
1719
+        if ( $use_conditional_logic ) {
1720 1720
             return $form;
1721 1721
         }
1722 1722
 
1723
-        foreach( $form['fields'] as &$field ) {
1723
+        foreach ( $form[ 'fields' ] as &$field ) {
1724 1724
             /* @var GF_Field $field */
1725 1725
             $field->conditionalLogic = null;
1726 1726
         }
1727 1727
 
1728
-        unset( $form['button']['conditionalLogic'] );
1728
+        unset( $form[ 'button' ][ 'conditionalLogic' ] );
1729 1729
 
1730 1730
         return $form;
1731 1731
 
@@ -1742,7 +1742,7 @@  discard block
 block discarded – undo
1742 1742
      */
1743 1743
     function manage_conditional_logic( $has_conditional_logic, $form ) {
1744 1744
 
1745
-        if( ! $this->is_edit_entry() ) {
1745
+        if ( ! $this->is_edit_entry() ) {
1746 1746
             return $has_conditional_logic;
1747 1747
         }
1748 1748
 
@@ -1773,44 +1773,44 @@  discard block
 block discarded – undo
1773 1773
          *  2. There are two entries embedded using oEmbed
1774 1774
          *  3. One of the entries has just been saved
1775 1775
          */
1776
-        if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) {
1776
+        if ( ! empty( $_POST[ 'lid' ] ) && ! empty( $_GET[ 'entry' ] ) && ( $_POST[ 'lid' ] !== $_GET[ 'entry' ] ) ) {
1777 1777
 
1778 1778
             $error = true;
1779 1779
 
1780 1780
         }
1781 1781
 
1782
-        if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) {
1782
+        if ( ! empty( $_GET[ 'entry' ] ) && (string)$this->entry[ 'id' ] !== $_GET[ 'entry' ] ) {
1783 1783
 
1784 1784
             $error = true;
1785 1785
 
1786
-        } elseif( ! $this->verify_nonce() ) {
1786
+        } elseif ( ! $this->verify_nonce() ) {
1787 1787
 
1788 1788
             /**
1789 1789
              * If the Entry is embedded, there may be two entries on the same page.
1790 1790
              * If that's the case, and one is being edited, the other should fail gracefully and not display an error.
1791 1791
              */
1792
-            if( GravityView_oEmbed::getInstance()->get_entry_id() ) {
1792
+            if ( GravityView_oEmbed::getInstance()->get_entry_id() ) {
1793 1793
                 $error = true;
1794 1794
             } else {
1795
-                $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview');
1795
+                $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview' );
1796 1796
             }
1797 1797
 
1798 1798
         }
1799 1799
 
1800
-        if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) {
1801
-            $error = __( 'You do not have permission to edit this entry.', 'gravityview');
1800
+        if ( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) {
1801
+            $error = __( 'You do not have permission to edit this entry.', 'gravityview' );
1802 1802
         }
1803 1803
 
1804
-        if( $this->entry['status'] === 'trash' ) {
1805
-            $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' );
1804
+        if ( $this->entry[ 'status' ] === 'trash' ) {
1805
+            $error = __( 'You cannot edit the entry; it is in the trash.', 'gravityview' );
1806 1806
         }
1807 1807
 
1808 1808
         // No errors; everything's fine here!
1809
-        if( empty( $error ) ) {
1809
+        if ( empty( $error ) ) {
1810 1810
             return true;
1811 1811
         }
1812 1812
 
1813
-        if( $echo && $error !== true ) {
1813
+        if ( $echo && $error !== true ) {
1814 1814
 
1815 1815
 	        $error = esc_html( $error );
1816 1816
 
@@ -1818,13 +1818,13 @@  discard block
 block discarded – undo
1818 1818
 	         * @since 1.9
1819 1819
 	         */
1820 1820
 	        if ( ! empty( $this->entry ) ) {
1821
-		        $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;" ) );
1821
+		        $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;" ) );
1822 1822
 	        }
1823 1823
 
1824
-            echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error');
1824
+            echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error' );
1825 1825
         }
1826 1826
 
1827
-        do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error );
1827
+        do_action( 'gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error );
1828 1828
 
1829 1829
         return false;
1830 1830
     }
@@ -1841,20 +1841,20 @@  discard block
 block discarded – undo
1841 1841
 
1842 1842
         $error = NULL;
1843 1843
 
1844
-        if( ! $this->check_user_cap_edit_field( $field ) ) {
1845
-            $error = __( 'You do not have permission to edit this field.', 'gravityview');
1844
+        if ( ! $this->check_user_cap_edit_field( $field ) ) {
1845
+            $error = __( 'You do not have permission to edit this field.', 'gravityview' );
1846 1846
         }
1847 1847
 
1848 1848
         // No errors; everything's fine here!
1849
-        if( empty( $error ) ) {
1849
+        if ( empty( $error ) ) {
1850 1850
             return true;
1851 1851
         }
1852 1852
 
1853
-        if( $echo ) {
1854
-            echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error');
1853
+        if ( $echo ) {
1854
+            echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error' );
1855 1855
         }
1856 1856
 
1857
-        do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error );
1857
+        do_action( 'gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error );
1858 1858
 
1859 1859
         return false;
1860 1860
 
@@ -1872,15 +1872,15 @@  discard block
 block discarded – undo
1872 1872
     private function check_user_cap_edit_field( $field ) {
1873 1873
 
1874 1874
         // If they can edit any entries (as defined in Gravity Forms), we're good.
1875
-        if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) {
1875
+        if ( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) {
1876 1876
             return true;
1877 1877
         }
1878 1878
 
1879
-        $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false;
1879
+        $field_cap = isset( $field[ 'allow_edit_cap' ] ) ? $field[ 'allow_edit_cap' ] : false;
1880 1880
 
1881 1881
         // If the field has custom editing capaibilities set, check those
1882
-        if( $field_cap ) {
1883
-            return GVCommon::has_cap( $field['allow_edit_cap'] );
1882
+        if ( $field_cap ) {
1883
+            return GVCommon::has_cap( $field[ 'allow_edit_cap' ] );
1884 1884
         }
1885 1885
 
1886 1886
         return false;
@@ -1894,17 +1894,17 @@  discard block
 block discarded – undo
1894 1894
     public function verify_nonce() {
1895 1895
 
1896 1896
         // Verify form submitted for editing single
1897
-        if( $this->is_edit_entry_submission() ) {
1897
+        if ( $this->is_edit_entry_submission() ) {
1898 1898
             $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field );
1899 1899
         }
1900 1900
 
1901 1901
         // Verify
1902
-        else if( ! $this->is_edit_entry() ) {
1902
+        else if ( ! $this->is_edit_entry() ) {
1903 1903
             $valid = false;
1904 1904
         }
1905 1905
 
1906 1906
         else {
1907
-            $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key );
1907
+            $valid = wp_verify_nonce( $_GET[ 'edit' ], self::$nonce_key );
1908 1908
         }
1909 1909
 
1910 1910
         /**
Please login to merge, or discard this patch.
includes/extensions/edit-entry/class-edit-entry-user-registration.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@
 block discarded – undo
57 57
      * @since 1.11
58 58
      *
59 59
      * @param array $form Gravity Forms form array
60
-     * @param string $entry_id Gravity Forms entry ID
60
+     * @param integer $entry_id Gravity Forms entry ID
61 61
      * @return void
62 62
      */
63 63
     public function update_user( $form = array(), $entry_id = 0 ) {
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -171,11 +171,13 @@
 block discarded – undo
171 171
         $public_display['nickname']  = $profileuser->nickname;
172 172
         $public_display['username']  = $profileuser->user_login;
173 173
 
174
-        if ( !empty($profileuser->first_name) )
175
-            $public_display['firstname'] = $profileuser->first_name;
174
+        if ( !empty($profileuser->first_name) ) {
175
+                    $public_display['firstname'] = $profileuser->first_name;
176
+        }
176 177
 
177
-        if ( !empty($profileuser->last_name) )
178
-            $public_display['lastname'] = $profileuser->last_name;
178
+        if ( !empty($profileuser->last_name) ) {
179
+                    $public_display['lastname'] = $profileuser->last_name;
180
+        }
179 181
 
180 182
         if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) {
181 183
             $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name;
Please login to merge, or discard this patch.
Indentation   +243 added lines, -243 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  */
12 12
 
13 13
 if ( ! defined( 'WPINC' ) ) {
14
-    die;
14
+	die;
15 15
 }
16 16
 
17 17
 /**
@@ -22,255 +22,255 @@  discard block
 block discarded – undo
22 22
 	/**
23 23
 	 * @var GravityView_Edit_Entry
24 24
 	 */
25
-    protected $loader;
25
+	protected $loader;
26 26
 
27
-    /**
28
-     * @var WP_User|null Temporary storage used by restore_user_details()
29
-     */
30
-    private $_user_before_update = null;
27
+	/**
28
+	 * @var WP_User|null Temporary storage used by restore_user_details()
29
+	 */
30
+	private $_user_before_update = null;
31 31
 
32
-    function __construct( GravityView_Edit_Entry $loader ) {
33
-        $this->loader = $loader;
34
-    }
32
+	function __construct( GravityView_Edit_Entry $loader ) {
33
+		$this->loader = $loader;
34
+	}
35 35
 
36 36
 	/**
37 37
 	 * @since 1.11
38 38
 	 */
39 39
 	public function load() {
40 40
 
41
-        /**
42
-	     * @filter `gravityview/edit_entry/user_registration/trigger_update` Choose whether to update user information via User Registration add-on when an entry is updated?
43
-	     * @since 1.11
44
-	     * @param boolean $boolean Whether to trigger update on user registration (default: true)
45
-	     */
46
-        if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) {
47
-            add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 );
48
-
49
-            // last resort in case the current user display name don't match any of the defaults
50
-            add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 );
51
-        }
52
-    }
53
-
54
-    /**
55
-     * Update the WordPress user profile based on the GF User Registration create feed
56
-     *
57
-     * @since 1.11
58
-     *
59
-     * @param array $form Gravity Forms form array
60
-     * @param string $entry_id Gravity Forms entry ID
61
-     * @return void
62
-     */
63
-    public function update_user( $form = array(), $entry_id = 0 ) {
64
-
65
-        if( !class_exists( 'GFAPI' ) || !class_exists( 'GFUser' ) || empty( $entry_id ) ) {
66
-            return;
67
-        }
68
-
69
-        // support for GF User Registration 3.x
70
-        $gf_user_3 =  class_exists('GF_User_Registration') ? true : false;
71
-
72
-        if( $gf_user_3 ) {
73
-            $gf_user_registration = GF_User_Registration::get_instance();
74
-        }
75
-
76
-        $entry = GFAPI::get_entry( $entry_id );
77
-
78
-	    /**
79
-	     * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on
80
-	     * @since 1.11
81
-	     * @param array $entry Gravity Forms entry
82
-	     * @param array $form Gravity Forms form
83
-	     */
84
-        $entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form );
85
-
86
-        /**
87
-         * @since 1.14
88
-         */
89
-        if( $gf_user_3 ) {
90
-            $config = $gf_user_registration->get_single_submission_feed( $entry, $form );
91
-        } else {
92
-            $config = GFUser::get_active_config( $form, $entry );
93
-        }
94
-
95
-        /**
96
-         * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed
97
-         * @since 1.15
98
-         * @param[in,out] boolean $preserve_role Preserve current user role Default: true
99
-         * @param[in] array $config Gravity Forms User Registration feed configuration for the form
100
-         * @param[in] array $form Gravity Forms form array
101
-         * @param[in] array $entry Gravity Forms entry being edited
102
-         */
103
-        $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry );
104
-
105
-        if( $preserve_role ) {
106
-            $config['meta']['role'] = 'gfur_preserve_role';
107
-        }
108
-
109
-        /**
110
-         * Make sure the current display name is not changed with the update user method.
111
-         * @since 1.15
112
-         */
113
-        $config['meta']['displayname'] = $this->match_current_display_name( $entry['created_by'] );
114
-
115
-
116
-        /**
117
-         * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration
118
-         * @since 1.14
119
-         * @param[in,out] array $config Gravity Forms User Registration feed configuration for the form
120
-         * @param[in] array $form Gravity Forms form array
121
-         * @param[in] array $entry Gravity Forms entry being edited
122
-         */
123
-        $config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry );
124
-
125
-
126
-        $feed_pos = $gf_user_3 ? 'meta/feedType' : 'meta/feed_type';
127
-        $is_create_feed = ( $config && rgars( $config, $feed_pos ) === 'create' );
128
-
129
-        // Only update if it's a create feed
130
-        if( ! $is_create_feed ) {
131
-            return;
132
-        }
133
-
134
-        // The priority is set to 3 so that default priority (10) will still override it
135
-        add_filter( 'send_password_change_email', '__return_false', 3 );
136
-        add_filter( 'send_email_change_email', '__return_false', 3 );
137
-
138
-        // Trigger the User Registration update user method
139
-        if( $gf_user_3 ) {
140
-            $gf_user_registration->update_user( $entry, $form, $config );
141
-        } else {
142
-            GFUser::update_user( $entry, $form, $config );
143
-        }
144
-
145
-
146
-        remove_filter( 'send_password_change_email', '__return_false', 3 );
147
-        remove_filter( 'send_email_change_email', '__return_false', 3 );
148
-
149
-    }
150
-
151
-    /**
152
-     * Calculate the user display name format
153
-     *
154
-     * @since 1.15
155
-     *
156
-     * @param int $user_id WP User ID
157
-     * @return string Display name format as used inside Gravity Forms User Registration
158
-     */
159
-    public function match_current_display_name( $user_id ) {
160
-
161
-        $user = get_userdata( $user_id );
162
-
163
-        $names = $this->generate_display_names( $user );
164
-
165
-        $format = array_search( $user->display_name, $names, true );
166
-
167
-        // In case we can't find the current display name format, or it is the 'nickname' format (which Gravity Forms doesn't support)
168
-        //   trigger last resort method at the 'gform_user_updated' hook
169
-        if( false === $format || 'nickname' === $format ) {
170
-            $this->_user_before_update = $user;
171
-            $format = 'nickname';
172
-        }
173
-
174
-        return $format;
175
-
176
-    }
177
-
178
-    /**
179
-     * Generate an array of all the user display names possibilities
180
-     *
181
-     * @since 1.15
182
-     *
183
-     * @param object $profileuser WP_User object
184
-     * @return array List all the possible display names for a certain User object
185
-     */
186
-    public function generate_display_names( $profileuser ) {
187
-
188
-        $public_display = array();
189
-        $public_display['nickname']  = $profileuser->nickname;
190
-        $public_display['username']  = $profileuser->user_login;
191
-
192
-        if ( !empty($profileuser->first_name) )
193
-            $public_display['firstname'] = $profileuser->first_name;
194
-
195
-        if ( !empty($profileuser->last_name) )
196
-            $public_display['lastname'] = $profileuser->last_name;
197
-
198
-        if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) {
199
-            $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name;
200
-            $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name;
201
-        }
202
-
203
-        $public_display = array_map( 'trim', $public_display );
204
-        $public_display = array_unique( $public_display );
205
-
206
-        return $public_display;
207
-    }
208
-
209
-
210
-    /**
211
-     * Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration Addon
212
-     *
213
-     * @see GFUser::update_user()
214
-     * @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon
215
-     * @param array $config Gravity Forms User Registration Addon form feed configuration
216
-     * @param array $entry The Gravity Forms entry that was just updated
217
-     * @param string $password User password
218
-     * @return void
219
-     */
220
-    public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) {
221
-
222
-        /**
223
-         * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry.
224
-         * Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed
225
-         * @since 1.14.4
226
-         * @param boolean $restore_display_name Restore Display Name? Default: true
227
-         */
228
-        $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true );
229
-
230
-        $is_update_feed = ( $config && rgars( $config, 'meta/feed_type') === 'update' );
231
-
232
-        /**
233
-         * Don't restore display name:
234
-         *   - either disabled,
235
-         *   - or it is an Update feed (we only care about Create feed)
236
-         *   - or we don't need as we found the correct format before updating user.
237
-         * @since 1.14.4
238
-         */
239
-        if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) {
240
-            return;
241
-        }
242
-
243
-        $user_after_update = get_userdata( $user_id );
244
-
245
-        $restored_user = $user_after_update;
246
-
247
-	    // Restore previous display_name
248
-        $restored_user->display_name = $this->_user_before_update->display_name;
249
-
250
-	    // Don't have WP update the password.
251
-	    unset( $restored_user->data->user_pass, $restored_user->user_pass );
252
-
253
-        /**
254
-         * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView
255
-         * @since 1.14
256
-         * @param WP_User $restored_user The user with restored details about to be updated by wp_update_user()
257
-         * @param WP_User $user_before_update The user before being updated by Gravity Forms User Registration
258
-         * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration
259
-         * @param array   $entry The Gravity Forms entry that was just updated
260
-         */
261
-        $restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry );
262
-
263
-        $updated = wp_update_user( $restored_user );
264
-
265
-        if( is_wp_error( $updated ) ) {
266
-            do_action('gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated );
267
-        } else {
268
-            do_action('gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) );
269
-        }
270
-
271
-        $this->_user_before_update = null;
272
-
273
-        unset( $updated, $restored_user, $user_after_update );
274
-    }
41
+		/**
42
+		 * @filter `gravityview/edit_entry/user_registration/trigger_update` Choose whether to update user information via User Registration add-on when an entry is updated?
43
+		 * @since 1.11
44
+		 * @param boolean $boolean Whether to trigger update on user registration (default: true)
45
+		 */
46
+		if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) {
47
+			add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 );
48
+
49
+			// last resort in case the current user display name don't match any of the defaults
50
+			add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 );
51
+		}
52
+	}
53
+
54
+	/**
55
+	 * Update the WordPress user profile based on the GF User Registration create feed
56
+	 *
57
+	 * @since 1.11
58
+	 *
59
+	 * @param array $form Gravity Forms form array
60
+	 * @param string $entry_id Gravity Forms entry ID
61
+	 * @return void
62
+	 */
63
+	public function update_user( $form = array(), $entry_id = 0 ) {
64
+
65
+		if( !class_exists( 'GFAPI' ) || !class_exists( 'GFUser' ) || empty( $entry_id ) ) {
66
+			return;
67
+		}
68
+
69
+		// support for GF User Registration 3.x
70
+		$gf_user_3 =  class_exists('GF_User_Registration') ? true : false;
71
+
72
+		if( $gf_user_3 ) {
73
+			$gf_user_registration = GF_User_Registration::get_instance();
74
+		}
75
+
76
+		$entry = GFAPI::get_entry( $entry_id );
77
+
78
+		/**
79
+		 * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on
80
+		 * @since 1.11
81
+		 * @param array $entry Gravity Forms entry
82
+		 * @param array $form Gravity Forms form
83
+		 */
84
+		$entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form );
85
+
86
+		/**
87
+		 * @since 1.14
88
+		 */
89
+		if( $gf_user_3 ) {
90
+			$config = $gf_user_registration->get_single_submission_feed( $entry, $form );
91
+		} else {
92
+			$config = GFUser::get_active_config( $form, $entry );
93
+		}
94
+
95
+		/**
96
+		 * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed
97
+		 * @since 1.15
98
+		 * @param[in,out] boolean $preserve_role Preserve current user role Default: true
99
+		 * @param[in] array $config Gravity Forms User Registration feed configuration for the form
100
+		 * @param[in] array $form Gravity Forms form array
101
+		 * @param[in] array $entry Gravity Forms entry being edited
102
+		 */
103
+		$preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry );
104
+
105
+		if( $preserve_role ) {
106
+			$config['meta']['role'] = 'gfur_preserve_role';
107
+		}
108
+
109
+		/**
110
+		 * Make sure the current display name is not changed with the update user method.
111
+		 * @since 1.15
112
+		 */
113
+		$config['meta']['displayname'] = $this->match_current_display_name( $entry['created_by'] );
114
+
115
+
116
+		/**
117
+		 * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration
118
+		 * @since 1.14
119
+		 * @param[in,out] array $config Gravity Forms User Registration feed configuration for the form
120
+		 * @param[in] array $form Gravity Forms form array
121
+		 * @param[in] array $entry Gravity Forms entry being edited
122
+		 */
123
+		$config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry );
124
+
125
+
126
+		$feed_pos = $gf_user_3 ? 'meta/feedType' : 'meta/feed_type';
127
+		$is_create_feed = ( $config && rgars( $config, $feed_pos ) === 'create' );
128
+
129
+		// Only update if it's a create feed
130
+		if( ! $is_create_feed ) {
131
+			return;
132
+		}
133
+
134
+		// The priority is set to 3 so that default priority (10) will still override it
135
+		add_filter( 'send_password_change_email', '__return_false', 3 );
136
+		add_filter( 'send_email_change_email', '__return_false', 3 );
137
+
138
+		// Trigger the User Registration update user method
139
+		if( $gf_user_3 ) {
140
+			$gf_user_registration->update_user( $entry, $form, $config );
141
+		} else {
142
+			GFUser::update_user( $entry, $form, $config );
143
+		}
144
+
145
+
146
+		remove_filter( 'send_password_change_email', '__return_false', 3 );
147
+		remove_filter( 'send_email_change_email', '__return_false', 3 );
148
+
149
+	}
150
+
151
+	/**
152
+	 * Calculate the user display name format
153
+	 *
154
+	 * @since 1.15
155
+	 *
156
+	 * @param int $user_id WP User ID
157
+	 * @return string Display name format as used inside Gravity Forms User Registration
158
+	 */
159
+	public function match_current_display_name( $user_id ) {
160
+
161
+		$user = get_userdata( $user_id );
162
+
163
+		$names = $this->generate_display_names( $user );
164
+
165
+		$format = array_search( $user->display_name, $names, true );
166
+
167
+		// In case we can't find the current display name format, or it is the 'nickname' format (which Gravity Forms doesn't support)
168
+		//   trigger last resort method at the 'gform_user_updated' hook
169
+		if( false === $format || 'nickname' === $format ) {
170
+			$this->_user_before_update = $user;
171
+			$format = 'nickname';
172
+		}
173
+
174
+		return $format;
175
+
176
+	}
177
+
178
+	/**
179
+	 * Generate an array of all the user display names possibilities
180
+	 *
181
+	 * @since 1.15
182
+	 *
183
+	 * @param object $profileuser WP_User object
184
+	 * @return array List all the possible display names for a certain User object
185
+	 */
186
+	public function generate_display_names( $profileuser ) {
187
+
188
+		$public_display = array();
189
+		$public_display['nickname']  = $profileuser->nickname;
190
+		$public_display['username']  = $profileuser->user_login;
191
+
192
+		if ( !empty($profileuser->first_name) )
193
+			$public_display['firstname'] = $profileuser->first_name;
194
+
195
+		if ( !empty($profileuser->last_name) )
196
+			$public_display['lastname'] = $profileuser->last_name;
197
+
198
+		if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) {
199
+			$public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name;
200
+			$public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name;
201
+		}
202
+
203
+		$public_display = array_map( 'trim', $public_display );
204
+		$public_display = array_unique( $public_display );
205
+
206
+		return $public_display;
207
+	}
208
+
209
+
210
+	/**
211
+	 * Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration Addon
212
+	 *
213
+	 * @see GFUser::update_user()
214
+	 * @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon
215
+	 * @param array $config Gravity Forms User Registration Addon form feed configuration
216
+	 * @param array $entry The Gravity Forms entry that was just updated
217
+	 * @param string $password User password
218
+	 * @return void
219
+	 */
220
+	public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) {
221
+
222
+		/**
223
+		 * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry.
224
+		 * Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed
225
+		 * @since 1.14.4
226
+		 * @param boolean $restore_display_name Restore Display Name? Default: true
227
+		 */
228
+		$restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true );
229
+
230
+		$is_update_feed = ( $config && rgars( $config, 'meta/feed_type') === 'update' );
231
+
232
+		/**
233
+		 * Don't restore display name:
234
+		 *   - either disabled,
235
+		 *   - or it is an Update feed (we only care about Create feed)
236
+		 *   - or we don't need as we found the correct format before updating user.
237
+		 * @since 1.14.4
238
+		 */
239
+		if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) {
240
+			return;
241
+		}
242
+
243
+		$user_after_update = get_userdata( $user_id );
244
+
245
+		$restored_user = $user_after_update;
246
+
247
+		// Restore previous display_name
248
+		$restored_user->display_name = $this->_user_before_update->display_name;
249
+
250
+		// Don't have WP update the password.
251
+		unset( $restored_user->data->user_pass, $restored_user->user_pass );
252
+
253
+		/**
254
+		 * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView
255
+		 * @since 1.14
256
+		 * @param WP_User $restored_user The user with restored details about to be updated by wp_update_user()
257
+		 * @param WP_User $user_before_update The user before being updated by Gravity Forms User Registration
258
+		 * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration
259
+		 * @param array   $entry The Gravity Forms entry that was just updated
260
+		 */
261
+		$restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry );
262
+
263
+		$updated = wp_update_user( $restored_user );
264
+
265
+		if( is_wp_error( $updated ) ) {
266
+			do_action('gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated );
267
+		} else {
268
+			do_action('gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) );
269
+		}
270
+
271
+		$this->_user_before_update = null;
272
+
273
+		unset( $updated, $restored_user, $user_after_update );
274
+	}
275 275
 
276 276
 } //end class
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 	     * @since 1.11
44 44
 	     * @param boolean $boolean Whether to trigger update on user registration (default: true)
45 45
 	     */
46
-        if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) {
47
-            add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 );
46
+        if ( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) {
47
+            add_action( 'gravityview/edit_entry/after_update', array( $this, 'update_user' ), 10, 2 );
48 48
 
49 49
             // last resort in case the current user display name don't match any of the defaults
50 50
             add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 );
@@ -62,14 +62,14 @@  discard block
 block discarded – undo
62 62
      */
63 63
     public function update_user( $form = array(), $entry_id = 0 ) {
64 64
 
65
-        if( !class_exists( 'GFAPI' ) || !class_exists( 'GFUser' ) || empty( $entry_id ) ) {
65
+        if ( ! class_exists( 'GFAPI' ) || ! class_exists( 'GFUser' ) || empty( $entry_id ) ) {
66 66
             return;
67 67
         }
68 68
 
69 69
         // support for GF User Registration 3.x
70
-        $gf_user_3 =  class_exists('GF_User_Registration') ? true : false;
70
+        $gf_user_3 = class_exists( 'GF_User_Registration' ) ? true : false;
71 71
 
72
-        if( $gf_user_3 ) {
72
+        if ( $gf_user_3 ) {
73 73
             $gf_user_registration = GF_User_Registration::get_instance();
74 74
         }
75 75
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
         /**
87 87
          * @since 1.14
88 88
          */
89
-        if( $gf_user_3 ) {
89
+        if ( $gf_user_3 ) {
90 90
             $config = $gf_user_registration->get_single_submission_feed( $entry, $form );
91 91
         } else {
92 92
             $config = GFUser::get_active_config( $form, $entry );
@@ -102,15 +102,15 @@  discard block
 block discarded – undo
102 102
          */
103 103
         $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry );
104 104
 
105
-        if( $preserve_role ) {
106
-            $config['meta']['role'] = 'gfur_preserve_role';
105
+        if ( $preserve_role ) {
106
+            $config[ 'meta' ][ 'role' ] = 'gfur_preserve_role';
107 107
         }
108 108
 
109 109
         /**
110 110
          * Make sure the current display name is not changed with the update user method.
111 111
          * @since 1.15
112 112
          */
113
-        $config['meta']['displayname'] = $this->match_current_display_name( $entry['created_by'] );
113
+        $config[ 'meta' ][ 'displayname' ] = $this->match_current_display_name( $entry[ 'created_by' ] );
114 114
 
115 115
 
116 116
         /**
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
         $is_create_feed = ( $config && rgars( $config, $feed_pos ) === 'create' );
128 128
 
129 129
         // Only update if it's a create feed
130
-        if( ! $is_create_feed ) {
130
+        if ( ! $is_create_feed ) {
131 131
             return;
132 132
         }
133 133
 
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
         add_filter( 'send_email_change_email', '__return_false', 3 );
137 137
 
138 138
         // Trigger the User Registration update user method
139
-        if( $gf_user_3 ) {
139
+        if ( $gf_user_3 ) {
140 140
             $gf_user_registration->update_user( $entry, $form, $config );
141 141
         } else {
142 142
             GFUser::update_user( $entry, $form, $config );
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 
167 167
         // In case we can't find the current display name format, or it is the 'nickname' format (which Gravity Forms doesn't support)
168 168
         //   trigger last resort method at the 'gform_user_updated' hook
169
-        if( false === $format || 'nickname' === $format ) {
169
+        if ( false === $format || 'nickname' === $format ) {
170 170
             $this->_user_before_update = $user;
171 171
             $format = 'nickname';
172 172
         }
@@ -186,18 +186,18 @@  discard block
 block discarded – undo
186 186
     public function generate_display_names( $profileuser ) {
187 187
 
188 188
         $public_display = array();
189
-        $public_display['nickname']  = $profileuser->nickname;
190
-        $public_display['username']  = $profileuser->user_login;
189
+        $public_display[ 'nickname' ]  = $profileuser->nickname;
190
+        $public_display[ 'username' ]  = $profileuser->user_login;
191 191
 
192
-        if ( !empty($profileuser->first_name) )
193
-            $public_display['firstname'] = $profileuser->first_name;
192
+        if ( ! empty( $profileuser->first_name ) )
193
+            $public_display[ 'firstname' ] = $profileuser->first_name;
194 194
 
195
-        if ( !empty($profileuser->last_name) )
196
-            $public_display['lastname'] = $profileuser->last_name;
195
+        if ( ! empty( $profileuser->last_name ) )
196
+            $public_display[ 'lastname' ] = $profileuser->last_name;
197 197
 
198
-        if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) {
199
-            $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name;
200
-            $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name;
198
+        if ( ! empty( $profileuser->first_name ) && ! empty( $profileuser->last_name ) ) {
199
+            $public_display[ 'firstlast' ] = $profileuser->first_name . ' ' . $profileuser->last_name;
200
+            $public_display[ 'lastfirst' ] = $profileuser->last_name . ' ' . $profileuser->first_name;
201 201
         }
202 202
 
203 203
         $public_display = array_map( 'trim', $public_display );
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
          */
228 228
         $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true );
229 229
 
230
-        $is_update_feed = ( $config && rgars( $config, 'meta/feed_type') === 'update' );
230
+        $is_update_feed = ( $config && rgars( $config, 'meta/feed_type' ) === 'update' );
231 231
 
232 232
         /**
233 233
          * Don't restore display name:
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
          *   - or we don't need as we found the correct format before updating user.
237 237
          * @since 1.14.4
238 238
          */
239
-        if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) {
239
+        if ( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) {
240 240
             return;
241 241
         }
242 242
 
@@ -262,10 +262,10 @@  discard block
 block discarded – undo
262 262
 
263 263
         $updated = wp_update_user( $restored_user );
264 264
 
265
-        if( is_wp_error( $updated ) ) {
266
-            do_action('gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated );
265
+        if ( is_wp_error( $updated ) ) {
266
+            do_action( 'gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated );
267 267
         } else {
268
-            do_action('gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) );
268
+            do_action( 'gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) );
269 269
         }
270 270
 
271 271
         $this->_user_before_update = null;
Please login to merge, or discard this patch.
includes/extensions/edit-entry/class-edit-entry.php 3 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,6 +65,9 @@  discard block
 block discarded – undo
65 65
     }
66 66
 
67 67
 
68
+    /**
69
+     * @param string $component
70
+     */
68 71
     private function load_components( $component ) {
69 72
 
70 73
         $dir = trailingslashit( self::$file );
@@ -141,7 +144,7 @@  discard block
 block discarded – undo
141 144
      * "You can edit this post from the post page" fields, for example.
142 145
      *
143 146
      * @param $entry array Gravity Forms entry object
144
-     * @param $view_id int GravityView view id
147
+     * @param integer $view_id int GravityView view id
145 148
      * @param $post_id int GravityView Post ID where View may be embedded {@since 1.9.2}
146 149
      * @param string|array $field_values Parameters to pass in to the Edit Entry form to prefill data. Uses the same format as Gravity Forms "Allow field to be populated dynamically" {@since 1.9.2} {@see https://www.gravityhelp.com/documentation/article/allow-field-to-be-populated-dynamically/ }
147 150
      * @return string
Please login to merge, or discard this patch.
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -18,80 +18,80 @@  discard block
 block discarded – undo
18 18
 
19 19
 class GravityView_Edit_Entry {
20 20
 
21
-    /**
22
-     * @var string
23
-     */
21
+	/**
22
+	 * @var string
23
+	 */
24 24
 	static $file;
25 25
 
26 26
 	static $instance;
27 27
 
28
-    /**
29
-     * Component instances.
30
-     * @var array
31
-     */
32
-    public $instances = array();
28
+	/**
29
+	 * Component instances.
30
+	 * @var array
31
+	 */
32
+	public $instances = array();
33 33
 
34 34
 
35 35
 	function __construct() {
36 36
 
37
-        self::$file = plugin_dir_path( __FILE__ );
37
+		self::$file = plugin_dir_path( __FILE__ );
38 38
 
39
-        if( is_admin() ) {
40
-            $this->load_components( 'admin' );
41
-        }
39
+		if( is_admin() ) {
40
+			$this->load_components( 'admin' );
41
+		}
42 42
 
43 43
 
44
-        $this->load_components( 'render' );
44
+		$this->load_components( 'render' );
45 45
 
46
-        // If GF User Registration Add-on exists
47
-        $this->load_components( 'user-registration' );
46
+		// If GF User Registration Add-on exists
47
+		$this->load_components( 'user-registration' );
48 48
 
49
-        $this->add_hooks();
49
+		$this->add_hooks();
50 50
 
51 51
 		// Process hooks for addons that may or may not be present
52 52
 		$this->addon_specific_hooks();
53 53
 	}
54 54
 
55 55
 
56
-    static function getInstance() {
56
+	static function getInstance() {
57 57
 
58
-        if( empty( self::$instance ) ) {
59
-            self::$instance = new GravityView_Edit_Entry;
60
-        }
58
+		if( empty( self::$instance ) ) {
59
+			self::$instance = new GravityView_Edit_Entry;
60
+		}
61 61
 
62
-        return self::$instance;
63
-    }
62
+		return self::$instance;
63
+	}
64 64
 
65 65
 
66
-    private function load_components( $component ) {
66
+	private function load_components( $component ) {
67 67
 
68
-        $dir = trailingslashit( self::$file );
68
+		$dir = trailingslashit( self::$file );
69 69
 
70
-        $filename  = $dir . 'class-edit-entry-' . $component . '.php';
71
-        $classname = 'GravityView_Edit_Entry_' . str_replace( ' ', '_', ucwords( str_replace( '-', ' ', $component ) ) );
70
+		$filename  = $dir . 'class-edit-entry-' . $component . '.php';
71
+		$classname = 'GravityView_Edit_Entry_' . str_replace( ' ', '_', ucwords( str_replace( '-', ' ', $component ) ) );
72 72
 
73
-        // Loads component and pass extension's instance so that component can
74
-        // talk each other.
75
-        require_once $filename;
76
-        $this->instances[ $component ] = new $classname( $this );
77
-        $this->instances[ $component ]->load();
73
+		// Loads component and pass extension's instance so that component can
74
+		// talk each other.
75
+		require_once $filename;
76
+		$this->instances[ $component ] = new $classname( $this );
77
+		$this->instances[ $component ]->load();
78 78
 
79
-    }
79
+	}
80 80
 
81
-    private function add_hooks() {
81
+	private function add_hooks() {
82 82
 
83
-        // Add front-end access to Gravity Forms delete file action
84
-        add_action( 'wp_ajax_nopriv_rg_delete_file', array( 'RGForms', 'delete_file') );
83
+		// Add front-end access to Gravity Forms delete file action
84
+		add_action( 'wp_ajax_nopriv_rg_delete_file', array( 'RGForms', 'delete_file') );
85 85
 
86
-        // Make sure this hook is run for non-admins
87
-        add_action( 'wp_ajax_rg_delete_file', array( 'RGForms', 'delete_file') );
86
+		// Make sure this hook is run for non-admins
87
+		add_action( 'wp_ajax_rg_delete_file', array( 'RGForms', 'delete_file') );
88 88
 
89
-        add_filter( 'gravityview_blacklist_field_types', array( $this, 'modify_field_blacklist' ), 10, 2 );
89
+		add_filter( 'gravityview_blacklist_field_types', array( $this, 'modify_field_blacklist' ), 10, 2 );
90 90
 
91
-        // add template path to check for field
92
-        add_filter( 'gravityview_template_paths', array( $this, 'add_template_path' ) );
91
+		// add template path to check for field
92
+		add_filter( 'gravityview_template_paths', array( $this, 'add_template_path' ) );
93 93
 
94
-    }
94
+	}
95 95
 
96 96
 	/**
97 97
 	 * Trigger hooks that are normally run in the admin for Addons, but need to be triggered manually because we're not in the admin
@@ -105,75 +105,75 @@  discard block
 block discarded – undo
105 105
 
106 106
 	}
107 107
 
108
-    /**
109
-     * Include this extension templates path
110
-     * @param array $file_paths List of template paths ordered
111
-     */
112
-    public function add_template_path( $file_paths ) {
113
-
114
-        // Index 100 is the default GravityView template path.
115
-        $file_paths[ 110 ] = self::$file;
116
-
117
-        return $file_paths;
118
-    }
119
-
120
-    /**
121
-     *
122
-     * Return a well formatted nonce key according to GravityView Edit Entry protocol
123
-     *
124
-     * @param $view_id int GravityView view id
125
-     * @param $form_id int Gravity Forms form id
126
-     * @param $entry_id int Gravity Forms entry id
127
-     * @return string
128
-     */
129
-    public static function get_nonce_key( $view_id, $form_id, $entry_id ) {
130
-        return sprintf( 'edit_%d_%d_%d', $view_id, $form_id, $entry_id );
131
-    }
132
-
133
-
134
-    /**
135
-     * The edit entry link creates a secure link with a nonce
136
-     *
137
-     * It also mimics the URL structure Gravity Forms expects to have so that
138
-     * it formats the display of the edit form like it does in the backend, like
139
-     * "You can edit this post from the post page" fields, for example.
140
-     *
141
-     * @param $entry array Gravity Forms entry object
142
-     * @param $view_id int GravityView view id
143
-     * @param $post_id int GravityView Post ID where View may be embedded {@since 1.9.2}
144
-     * @param string|array $field_values Parameters to pass in to the Edit Entry form to prefill data. Uses the same format as Gravity Forms "Allow field to be populated dynamically" {@since 1.9.2} {@see https://www.gravityhelp.com/documentation/article/allow-field-to-be-populated-dynamically/ }
145
-     * @return string
146
-     */
147
-    public static function get_edit_link( $entry, $view_id, $post_id = null, $field_values = '' ) {
148
-
149
-        $nonce_key = self::get_nonce_key( $view_id, $entry['form_id'], $entry['id']  );
150
-
151
-        $base = gv_entry_link( $entry, $post_id );
152
-
153
-        $url = add_query_arg( array(
154
-            'page' => 'gf_entries', // Needed for GFForms::get_page()
155
-            'view' => 'entry', // Needed for GFForms::get_page()
156
-            'edit' => wp_create_nonce( $nonce_key )
157
-        ), $base );
158
-
159
-	    /**
160
-	     * Allow passing params to dynamically populate entry with values
161
-	     * @since 1.9.2
162
-	     */
163
-	    if( !empty( $field_values ) ) {
164
-
165
-		    if( is_array( $field_values ) ) {
166
-			    // If already an array, no parse_str() needed
167
-			    $params = $field_values;
168
-		    } else {
169
-			    parse_str( $field_values, $params );
170
-		    }
171
-
172
-		    $url = add_query_arg( $params, $url );
173
-	    }
174
-
175
-        return $url;
176
-    }
108
+	/**
109
+	 * Include this extension templates path
110
+	 * @param array $file_paths List of template paths ordered
111
+	 */
112
+	public function add_template_path( $file_paths ) {
113
+
114
+		// Index 100 is the default GravityView template path.
115
+		$file_paths[ 110 ] = self::$file;
116
+
117
+		return $file_paths;
118
+	}
119
+
120
+	/**
121
+	 *
122
+	 * Return a well formatted nonce key according to GravityView Edit Entry protocol
123
+	 *
124
+	 * @param $view_id int GravityView view id
125
+	 * @param $form_id int Gravity Forms form id
126
+	 * @param $entry_id int Gravity Forms entry id
127
+	 * @return string
128
+	 */
129
+	public static function get_nonce_key( $view_id, $form_id, $entry_id ) {
130
+		return sprintf( 'edit_%d_%d_%d', $view_id, $form_id, $entry_id );
131
+	}
132
+
133
+
134
+	/**
135
+	 * The edit entry link creates a secure link with a nonce
136
+	 *
137
+	 * It also mimics the URL structure Gravity Forms expects to have so that
138
+	 * it formats the display of the edit form like it does in the backend, like
139
+	 * "You can edit this post from the post page" fields, for example.
140
+	 *
141
+	 * @param $entry array Gravity Forms entry object
142
+	 * @param $view_id int GravityView view id
143
+	 * @param $post_id int GravityView Post ID where View may be embedded {@since 1.9.2}
144
+	 * @param string|array $field_values Parameters to pass in to the Edit Entry form to prefill data. Uses the same format as Gravity Forms "Allow field to be populated dynamically" {@since 1.9.2} {@see https://www.gravityhelp.com/documentation/article/allow-field-to-be-populated-dynamically/ }
145
+	 * @return string
146
+	 */
147
+	public static function get_edit_link( $entry, $view_id, $post_id = null, $field_values = '' ) {
148
+
149
+		$nonce_key = self::get_nonce_key( $view_id, $entry['form_id'], $entry['id']  );
150
+
151
+		$base = gv_entry_link( $entry, $post_id );
152
+
153
+		$url = add_query_arg( array(
154
+			'page' => 'gf_entries', // Needed for GFForms::get_page()
155
+			'view' => 'entry', // Needed for GFForms::get_page()
156
+			'edit' => wp_create_nonce( $nonce_key )
157
+		), $base );
158
+
159
+		/**
160
+		 * Allow passing params to dynamically populate entry with values
161
+		 * @since 1.9.2
162
+		 */
163
+		if( !empty( $field_values ) ) {
164
+
165
+			if( is_array( $field_values ) ) {
166
+				// If already an array, no parse_str() needed
167
+				$params = $field_values;
168
+			} else {
169
+				parse_str( $field_values, $params );
170
+			}
171
+
172
+			$url = add_query_arg( $params, $url );
173
+		}
174
+
175
+		return $url;
176
+	}
177 177
 
178 178
 
179 179
 	/**
@@ -209,81 +209,81 @@  discard block
 block discarded – undo
209 209
 	}
210 210
 
211 211
 
212
-    /**
213
-     * checks if user has permissions to edit a specific entry
214
-     *
215
-     * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_entry for maximum security!!
216
-     *
217
-     * @param  array $entry Gravity Forms entry array
218
-     * @param int $view_id ID of the view you want to check visibility against {@since 1.9.2}
219
-     * @return bool
220
-     */
221
-    public static function check_user_cap_edit_entry( $entry, $view_id = 0 ) {
212
+	/**
213
+	 * checks if user has permissions to edit a specific entry
214
+	 *
215
+	 * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_entry for maximum security!!
216
+	 *
217
+	 * @param  array $entry Gravity Forms entry array
218
+	 * @param int $view_id ID of the view you want to check visibility against {@since 1.9.2}
219
+	 * @return bool
220
+	 */
221
+	public static function check_user_cap_edit_entry( $entry, $view_id = 0 ) {
222 222
 
223
-        // No permission by default
224
-        $user_can_edit = false;
223
+		// No permission by default
224
+		$user_can_edit = false;
225 225
 
226
-        // If they can edit any entries (as defined in Gravity Forms)
227
-        // Or if they can edit other people's entries
228
-        // Then we're good.
229
-        if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ), $entry['id'] ) ) {
226
+		// If they can edit any entries (as defined in Gravity Forms)
227
+		// Or if they can edit other people's entries
228
+		// Then we're good.
229
+		if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ), $entry['id'] ) ) {
230 230
 
231
-            do_action('gravityview_log_debug', __METHOD__ . ' - User has ability to edit all entries.');
231
+			do_action('gravityview_log_debug', __METHOD__ . ' - User has ability to edit all entries.');
232 232
 
233
-            $user_can_edit = true;
233
+			$user_can_edit = true;
234 234
 
235
-        } else if( !isset( $entry['created_by'] ) ) {
235
+		} else if( !isset( $entry['created_by'] ) ) {
236 236
 
237
-            do_action('gravityview_log_error', 'GravityView_Edit_Entry[check_user_cap_edit_entry] Entry `created_by` doesn\'t exist.');
237
+			do_action('gravityview_log_error', 'GravityView_Edit_Entry[check_user_cap_edit_entry] Entry `created_by` doesn\'t exist.');
238 238
 
239
-            $user_can_edit = false;
239
+			$user_can_edit = false;
240 240
 
241
-        } else {
241
+		} else {
242 242
 
243
-            // get user_edit setting
244
-            if( empty( $view_id ) || $view_id == GravityView_View::getInstance()->getViewId() ) {
245
-                // if View ID not specified or is the current view
246
-                $user_edit = GravityView_View::getInstance()->getAtts('user_edit');
247
-            } else {
248
-                // in case is specified and not the current view
249
-                $user_edit = GVCommon::get_template_setting( $view_id, 'user_edit' );
250
-            }
243
+			// get user_edit setting
244
+			if( empty( $view_id ) || $view_id == GravityView_View::getInstance()->getViewId() ) {
245
+				// if View ID not specified or is the current view
246
+				$user_edit = GravityView_View::getInstance()->getAtts('user_edit');
247
+			} else {
248
+				// in case is specified and not the current view
249
+				$user_edit = GVCommon::get_template_setting( $view_id, 'user_edit' );
250
+			}
251 251
 
252
-            $current_user = wp_get_current_user();
252
+			$current_user = wp_get_current_user();
253 253
 
254
-            // User edit is disabled
255
-            if( empty( $user_edit ) ) {
254
+			// User edit is disabled
255
+			if( empty( $user_edit ) ) {
256 256
 
257
-                do_action('gravityview_log_debug', 'GravityView_Edit_Entry[check_user_cap_edit_entry] User Edit is disabled. Returning false.' );
257
+				do_action('gravityview_log_debug', 'GravityView_Edit_Entry[check_user_cap_edit_entry] User Edit is disabled. Returning false.' );
258 258
 
259
-                $user_can_edit = false;
260
-            }
259
+				$user_can_edit = false;
260
+			}
261 261
 
262
-            // User edit is enabled and the logged-in user is the same as the user who created the entry. We're good.
263
-            else if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) {
262
+			// User edit is enabled and the logged-in user is the same as the user who created the entry. We're good.
263
+			else if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) {
264 264
 
265
-                do_action('gravityview_log_debug', sprintf( 'GravityView_Edit_Entry[check_user_cap_edit_entry] User %s created the entry.', $current_user->ID ) );
265
+				do_action('gravityview_log_debug', sprintf( 'GravityView_Edit_Entry[check_user_cap_edit_entry] User %s created the entry.', $current_user->ID ) );
266 266
 
267
-                $user_can_edit = true;
267
+				$user_can_edit = true;
268 268
 
269
-            } else if( ! is_user_logged_in() ) {
269
+			} else if( ! is_user_logged_in() ) {
270 270
 
271
-                do_action( 'gravityview_log_debug', __METHOD__ . ' No user defined; edit entry requires logged in user' );
272
-            }
271
+				do_action( 'gravityview_log_debug', __METHOD__ . ' No user defined; edit entry requires logged in user' );
272
+			}
273 273
 
274
-        }
274
+		}
275 275
 
276
-        /**
277
-         * @filter `gravityview/edit_entry/user_can_edit_entry` Modify whether user can edit an entry.
278
-         * @since 1.15 Added `$entry` and `$view_id` parameters
279
-         * @param[in,out] boolean $user_can_edit Can the current user edit the current entry? (Default: false)
280
-         * @param[in] array $entry Gravity Forms entry array {@since 1.15}
281
-         * @param[in] int $view_id ID of the view you want to check visibility against {@since 1.15}
282
-         */
283
-        $user_can_edit = apply_filters( 'gravityview/edit_entry/user_can_edit_entry', $user_can_edit, $entry, $view_id );
276
+		/**
277
+		 * @filter `gravityview/edit_entry/user_can_edit_entry` Modify whether user can edit an entry.
278
+		 * @since 1.15 Added `$entry` and `$view_id` parameters
279
+		 * @param[in,out] boolean $user_can_edit Can the current user edit the current entry? (Default: false)
280
+		 * @param[in] array $entry Gravity Forms entry array {@since 1.15}
281
+		 * @param[in] int $view_id ID of the view you want to check visibility against {@since 1.15}
282
+		 */
283
+		$user_can_edit = apply_filters( 'gravityview/edit_entry/user_can_edit_entry', $user_can_edit, $entry, $view_id );
284 284
 
285
-        return (bool)$user_can_edit;
286
-    }
285
+		return (bool)$user_can_edit;
286
+	}
287 287
 
288 288
 
289 289
 
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 
37 37
         self::$file = plugin_dir_path( __FILE__ );
38 38
 
39
-        if( is_admin() ) {
39
+        if ( is_admin() ) {
40 40
             $this->load_components( 'admin' );
41 41
         }
42 42
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 
56 56
     static function getInstance() {
57 57
 
58
-        if( empty( self::$instance ) ) {
58
+        if ( empty( self::$instance ) ) {
59 59
             self::$instance = new GravityView_Edit_Entry;
60 60
         }
61 61
 
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
     private function add_hooks() {
82 82
 
83 83
         // Add front-end access to Gravity Forms delete file action
84
-        add_action( 'wp_ajax_nopriv_rg_delete_file', array( 'RGForms', 'delete_file') );
84
+        add_action( 'wp_ajax_nopriv_rg_delete_file', array( 'RGForms', 'delete_file' ) );
85 85
 
86 86
         // Make sure this hook is run for non-admins
87
-        add_action( 'wp_ajax_rg_delete_file', array( 'RGForms', 'delete_file') );
87
+        add_action( 'wp_ajax_rg_delete_file', array( 'RGForms', 'delete_file' ) );
88 88
 
89 89
         add_filter( 'gravityview_blacklist_field_types', array( $this, 'modify_field_blacklist' ), 10, 2 );
90 90
 
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
 	 */
100 100
 	private function addon_specific_hooks() {
101 101
 
102
-		if( class_exists( 'GFSignature' ) && is_callable( array( 'GFSignature', 'get_instance' ) ) ) {
103
-			add_filter('gform_admin_pre_render', array( GFSignature::get_instance(), 'edit_lead_script'));
102
+		if ( class_exists( 'GFSignature' ) && is_callable( array( 'GFSignature', 'get_instance' ) ) ) {
103
+			add_filter( 'gform_admin_pre_render', array( GFSignature::get_instance(), 'edit_lead_script' ) );
104 104
 		}
105 105
 
106 106
 	}
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
      */
147 147
     public static function get_edit_link( $entry, $view_id, $post_id = null, $field_values = '' ) {
148 148
 
149
-        $nonce_key = self::get_nonce_key( $view_id, $entry['form_id'], $entry['id']  );
149
+        $nonce_key = self::get_nonce_key( $view_id, $entry[ 'form_id' ], $entry[ 'id' ] );
150 150
 
151 151
         $base = gv_entry_link( $entry, $post_id );
152 152
 
@@ -160,9 +160,9 @@  discard block
 block discarded – undo
160 160
 	     * Allow passing params to dynamically populate entry with values
161 161
 	     * @since 1.9.2
162 162
 	     */
163
-	    if( !empty( $field_values ) ) {
163
+	    if ( ! empty( $field_values ) ) {
164 164
 
165
-		    if( is_array( $field_values ) ) {
165
+		    if ( is_array( $field_values ) ) {
166 166
 			    // If already an array, no parse_str() needed
167 167
 			    $params = $field_values;
168 168
 		    } else {
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 	 */
185 185
 	public function modify_field_blacklist( $fields = array(), $context = NULL ) {
186 186
 
187
-		if( empty( $context ) || $context !== 'edit' ) {
187
+		if ( empty( $context ) || $context !== 'edit' ) {
188 188
 			return $fields;
189 189
 		}
190 190
 
@@ -226,24 +226,24 @@  discard block
 block discarded – undo
226 226
         // If they can edit any entries (as defined in Gravity Forms)
227 227
         // Or if they can edit other people's entries
228 228
         // Then we're good.
229
-        if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ), $entry['id'] ) ) {
229
+        if ( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ), $entry[ 'id' ] ) ) {
230 230
 
231
-            do_action('gravityview_log_debug', __METHOD__ . ' - User has ability to edit all entries.');
231
+            do_action( 'gravityview_log_debug', __METHOD__ . ' - User has ability to edit all entries.' );
232 232
 
233 233
             $user_can_edit = true;
234 234
 
235
-        } else if( !isset( $entry['created_by'] ) ) {
235
+        } else if ( ! isset( $entry[ 'created_by' ] ) ) {
236 236
 
237
-            do_action('gravityview_log_error', 'GravityView_Edit_Entry[check_user_cap_edit_entry] Entry `created_by` doesn\'t exist.');
237
+            do_action( 'gravityview_log_error', 'GravityView_Edit_Entry[check_user_cap_edit_entry] Entry `created_by` doesn\'t exist.' );
238 238
 
239 239
             $user_can_edit = false;
240 240
 
241 241
         } else {
242 242
 
243 243
             // get user_edit setting
244
-            if( empty( $view_id ) || $view_id == GravityView_View::getInstance()->getViewId() ) {
244
+            if ( empty( $view_id ) || $view_id == GravityView_View::getInstance()->getViewId() ) {
245 245
                 // if View ID not specified or is the current view
246
-                $user_edit = GravityView_View::getInstance()->getAtts('user_edit');
246
+                $user_edit = GravityView_View::getInstance()->getAtts( 'user_edit' );
247 247
             } else {
248 248
                 // in case is specified and not the current view
249 249
                 $user_edit = GVCommon::get_template_setting( $view_id, 'user_edit' );
@@ -252,21 +252,21 @@  discard block
 block discarded – undo
252 252
             $current_user = wp_get_current_user();
253 253
 
254 254
             // User edit is disabled
255
-            if( empty( $user_edit ) ) {
255
+            if ( empty( $user_edit ) ) {
256 256
 
257
-                do_action('gravityview_log_debug', 'GravityView_Edit_Entry[check_user_cap_edit_entry] User Edit is disabled. Returning false.' );
257
+                do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[check_user_cap_edit_entry] User Edit is disabled. Returning false.' );
258 258
 
259 259
                 $user_can_edit = false;
260 260
             }
261 261
 
262 262
             // User edit is enabled and the logged-in user is the same as the user who created the entry. We're good.
263
-            else if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) {
263
+            else if ( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry[ 'created_by' ] ) ) {
264 264
 
265
-                do_action('gravityview_log_debug', sprintf( 'GravityView_Edit_Entry[check_user_cap_edit_entry] User %s created the entry.', $current_user->ID ) );
265
+                do_action( 'gravityview_log_debug', sprintf( 'GravityView_Edit_Entry[check_user_cap_edit_entry] User %s created the entry.', $current_user->ID ) );
266 266
 
267 267
                 $user_can_edit = true;
268 268
 
269
-            } else if( ! is_user_logged_in() ) {
269
+            } else if ( ! is_user_logged_in() ) {
270 270
 
271 271
                 do_action( 'gravityview_log_debug', __METHOD__ . ' No user defined; edit entry requires logged in user' );
272 272
             }
Please login to merge, or discard this patch.
plugin-and-theme-hooks/abstract-gravityview-plugin-and-theme-hooks.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -169,7 +169,6 @@
 block discarded – undo
169 169
 	 *
170 170
 	 * @since 1.15.2
171 171
 	 *
172
-	 * @param array $handles Array of meta keys to check for existence of shortcodes
173 172
 	 * @param int $post_id The ID being checked by GravityView
174 173
 	 *
175 174
 	 * @return array Meta key array, merged with existing meta keys
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
 	private function maybe_add_hooks() {
92 92
 		$class_exists = $this->class_name && class_exists( $this->class_name );
93 93
 		$function_exists = $this->function_name && function_exists( $this->function_name );
94
-		$constant_defined = $this->constant_name && defined("{$this->constant_name}");
94
+		$constant_defined = $this->constant_name && defined( "{$this->constant_name}" );
95 95
 
96
-		if( $class_exists || $function_exists || $constant_defined ) {
96
+		if ( $class_exists || $function_exists || $constant_defined ) {
97 97
 			$this->add_hooks();
98 98
 		}
99 99
 	}
@@ -104,19 +104,19 @@  discard block
 block discarded – undo
104 104
 	 * @return void
105 105
 	 */
106 106
 	protected function add_hooks() {
107
-		if( $this->content_meta_keys ) {
107
+		if ( $this->content_meta_keys ) {
108 108
 			add_filter( 'gravityview/data/parse/meta_keys', array( $this, 'merge_content_meta_keys' ), 10, 2 );
109 109
 		}
110 110
 
111
-		if( $this->script_handles ) {
111
+		if ( $this->script_handles ) {
112 112
 			add_filter( 'gravityview_noconflict_scripts', array( $this, 'merge_noconflict_scripts' ) );
113 113
 		}
114 114
 
115
-		if( $this->style_handles ) {
115
+		if ( $this->style_handles ) {
116 116
 			add_filter( 'gravityview_noconflict_styles', array( $this, 'merge_noconflict_styles' ) );
117 117
 		}
118 118
 
119
-		if( $this->post_type_support ) {
119
+		if ( $this->post_type_support ) {
120 120
 			add_filter( 'gravityview_post_type_support', array( $this, 'merge_post_type_support' ), 10, 2 );
121 121
 		}
122 122
 	}
Please login to merge, or discard this patch.
includes/widgets/class-gravityview-widget.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -51,6 +51,9 @@
 block discarded – undo
51 51
 	// hold widget View options
52 52
 	private $widget_options;
53 53
 
54
+	/**
55
+	 * @param string $widget_id
56
+	 */
54 57
 	function __construct( $widget_label , $widget_id , $defaults = array(), $settings = array() ) {
55 58
 
56 59
 
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -116,12 +116,12 @@
 block discarded – undo
116 116
 		return $settings;
117 117
 	}
118 118
 
119
-    /**
120
-     * @return string
121
-     */
122
-    public function get_widget_id() {
123
-        return $this->widget_id;
124
-    }
119
+	/**
120
+	 * @return string
121
+	 */
122
+	public function get_widget_id() {
123
+		return $this->widget_id;
124
+	}
125 125
 
126 126
 	/**
127 127
 	 * Get the widget settings
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -51,14 +51,14 @@  discard block
 block discarded – undo
51 51
 	// hold widget View options
52 52
 	private $widget_options;
53 53
 
54
-	function __construct( $widget_label , $widget_id , $defaults = array(), $settings = array() ) {
54
+	function __construct( $widget_label, $widget_id, $defaults = array(), $settings = array() ) {
55 55
 
56 56
 
57 57
 		/**
58 58
 		 * The shortcode name is set to the lowercase name of the widget class, unless overridden by the class specifying a different value for $shortcode_name
59 59
 		 * @var string
60 60
 		 */
61
-		$this->shortcode_name = !isset( $this->shortcode_name ) ? strtolower( get_class($this) ) : $this->shortcode_name;
61
+		$this->shortcode_name = ! isset( $this->shortcode_name ) ? strtolower( get_class( $this ) ) : $this->shortcode_name;
62 62
 
63 63
 		$this->widget_label = $widget_label;
64 64
 		$this->widget_id = $widget_id;
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 		$this->settings = wp_parse_args( $settings, $this->settings );
70 70
 
71 71
 		// register widgets to be listed in the View Configuration
72
-		add_filter( 'gravityview_register_directory_widgets', array( $this, 'register_widget') );
72
+		add_filter( 'gravityview_register_directory_widgets', array( $this, 'register_widget' ) );
73 73
 
74 74
 		// widget options
75 75
 		add_filter( 'gravityview_template_widget_options', array( $this, 'assign_widget_options' ), 10, 3 );
@@ -78,10 +78,10 @@  discard block
 block discarded – undo
78 78
 		add_action( "gravityview_render_widget_{$widget_id}", array( $this, 'render_frontend' ), 10, 1 );
79 79
 
80 80
 		// register shortcodes
81
-		add_action( 'wp', array( $this, 'add_shortcode') );
81
+		add_action( 'wp', array( $this, 'add_shortcode' ) );
82 82
 
83 83
 		// Use shortcodes in text widgets.
84
-		add_filter('widget_text', array( $this, 'maybe_do_shortcode' ) );
84
+		add_filter( 'widget_text', array( $this, 'maybe_do_shortcode' ) );
85 85
 	}
86 86
 
87 87
 
@@ -99,14 +99,14 @@  discard block
 block discarded – undo
99 99
 		 * @param boolean $enable_custom_class False by default. Return true if you want to enable.
100 100
 		 * @param GravityView_Widget $this Current instance of GravityView_Widget
101 101
 		 */
102
-		$enable_custom_class = apply_filters('gravityview/widget/enable_custom_class', false, $this );
102
+		$enable_custom_class = apply_filters( 'gravityview/widget/enable_custom_class', false, $this );
103 103
 
104
-		if( $enable_custom_class ) {
104
+		if ( $enable_custom_class ) {
105 105
 
106
-			$settings['custom_class'] = array(
106
+			$settings[ 'custom_class' ] = array(
107 107
 				'type' => 'text',
108 108
 				'label' => __( 'Custom CSS Class:', 'gravityview' ),
109
-				'desc' => __( 'This class will be added to the widget container', 'gravityview'),
109
+				'desc' => __( 'This class will be added to the widget container', 'gravityview' ),
110 110
 				'value' => '',
111 111
 				'merge_tags' => true,
112 112
 			);
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 * @return array|null   Settings array; NULL if not set
129 129
 	 */
130 130
 	public function get_settings() {
131
-		return !empty( $this->settings ) ? $this->settings : NULL;
131
+		return ! empty( $this->settings ) ? $this->settings : NULL;
132 132
 	}
133 133
 
134 134
 	/**
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 	public function get_setting( $key ) {
140 140
 		$setting = NULL;
141 141
 
142
-		if( isset( $this->settings ) && is_array( $this->settings ) ) {
142
+		if ( isset( $this->settings ) && is_array( $this->settings ) ) {
143 143
 			$setting = isset( $this->settings[ $key ] ) ? $this->settings[ $key ] : NULL;
144 144
 		}
145 145
 
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 */
155 155
 	function maybe_do_shortcode( $text, $widget = NULL ) {
156 156
 
157
-		if( !empty( $this->shortcode_name ) && has_shortcode( $text, $this->shortcode_name ) ) {
157
+		if ( ! empty( $this->shortcode_name ) && has_shortcode( $text, $this->shortcode_name ) ) {
158 158
 			return do_shortcode( $text );
159 159
 		}
160 160
 
@@ -176,28 +176,28 @@  discard block
 block discarded – undo
176 176
 	function add_shortcode( $run_on_singular = true ) {
177 177
 		global $post;
178 178
 
179
-		if( GravityView_Plugin::is_admin() ) { return; }
179
+		if ( GravityView_Plugin::is_admin() ) { return; }
180 180
 
181
-		if( empty( $this->shortcode_name ) ) { return; }
181
+		if ( empty( $this->shortcode_name ) ) { return; }
182 182
 
183 183
 		// If the widget shouldn't output on single entries, don't show it
184
-		if( empty( $this->show_on_single ) && class_exists('GravityView_frontend') && GravityView_frontend::is_single_entry() ) {
185
-			do_action('gravityview_log_debug', sprintf( '%s[add_shortcode]: Skipping; set to not run on single entry.', get_class($this)) );
184
+		if ( empty( $this->show_on_single ) && class_exists( 'GravityView_frontend' ) && GravityView_frontend::is_single_entry() ) {
185
+			do_action( 'gravityview_log_debug', sprintf( '%s[add_shortcode]: Skipping; set to not run on single entry.', get_class( $this ) ) );
186 186
 
187 187
 			add_shortcode( $this->shortcode_name, '__return_null' );
188 188
 			return;
189 189
 		}
190 190
 
191 191
 
192
-		if( !has_gravityview_shortcode( $post ) ) {
192
+		if ( ! has_gravityview_shortcode( $post ) ) {
193 193
 
194
-			do_action('gravityview_log_debug', sprintf( '%s[add_shortcode]: No shortcode present; not adding render_frontend shortcode.', get_class($this)) );
194
+			do_action( 'gravityview_log_debug', sprintf( '%s[add_shortcode]: No shortcode present; not adding render_frontend shortcode.', get_class( $this ) ) );
195 195
 
196 196
 			add_shortcode( $this->shortcode_name, '__return_null' );
197 197
 			return;
198 198
 		}
199 199
 
200
-		add_shortcode( $this->shortcode_name, array( $this, 'render_shortcode') );
200
+		add_shortcode( $this->shortcode_name, array( $this, 'render_shortcode' ) );
201 201
 	}
202 202
 
203 203
 	/**
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 	 */
208 208
 	function register_widget( $widgets ) {
209 209
 		$widgets[ $this->widget_id ] = array(
210
-			'label' => $this->widget_label ,
210
+			'label' => $this->widget_label,
211 211
 			'description' => $this->widget_description,
212 212
 			'subtitle' => $this->widget_subtitle,
213 213
 		);
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 	 */
225 225
 	public function assign_widget_options( $options = array(), $template = '', $widget = '' ) {
226 226
 
227
-		if( $this->widget_id === $widget ) {
227
+		if ( $this->widget_id === $widget ) {
228 228
 			$options = array_merge( $options, $this->settings );
229 229
 		}
230 230
 
@@ -237,9 +237,9 @@  discard block
 block discarded – undo
237 237
 	 *
238 238
 	 * @return void
239 239
 	 */
240
-	public function render_frontend( $widget_args, $content = '', $context = '') {
240
+	public function render_frontend( $widget_args, $content = '', $context = '' ) {
241 241
 		// to be defined by child class
242
-		if( !$this->pre_render_frontend() ) {
242
+		if ( ! $this->pre_render_frontend() ) {
243 243
 			return;
244 244
 		}
245 245
 	}
@@ -251,8 +251,8 @@  discard block
 block discarded – undo
251 251
 	public function pre_render_frontend() {
252 252
 		$gravityview_view = GravityView_View::getInstance();
253 253
 
254
-		if( empty( $gravityview_view ) ) {
255
-			do_action('gravityview_log_debug', sprintf( '%s[render_frontend]: $gravityview_view not instantiated yet.', get_class($this)) );
254
+		if ( empty( $gravityview_view ) ) {
255
+			do_action( 'gravityview_log_debug', sprintf( '%s[render_frontend]: $gravityview_view not instantiated yet.', get_class( $this ) ) );
256 256
 			return false;
257 257
 		}
258 258
 
@@ -263,8 +263,8 @@  discard block
 block discarded – undo
263 263
 		 */
264 264
 		$hide_until_search = apply_filters( 'gravityview/widget/hide_until_searched', $gravityview_view->hide_until_searched, $this );
265 265
 
266
-		if( $hide_until_search ) {
267
-			do_action('gravityview_log_debug', sprintf( '%s[render_frontend]: Hide View data until search is performed', get_class($this)) );
266
+		if ( $hide_until_search ) {
267
+			do_action( 'gravityview_log_debug', sprintf( '%s[render_frontend]: Hide View data until search is performed', get_class( $this ) ) );
268 268
 			return false;
269 269
 		}
270 270
 
Please login to merge, or discard this patch.