Completed
Push — develop ( 6d2ec4...62ab4f )
by Gennady
41:32
created
includes/extensions/edit-entry/class-edit-entry-render.php 1 patch
Indentation   +283 added lines, -283 removed lines patch added patch discarded remove patch
@@ -94,10 +94,10 @@  discard block
 block discarded – undo
94 94
 
95 95
 	/**
96 96
 	 * ID of the current post. May also be ID of the current View.
97
-     *
98
-     * @since 2.0.13
99
-     * 
100
-     * @var int
97
+	 *
98
+	 * @since 2.0.13
99
+	 * 
100
+	 * @var int
101 101
 	 */
102 102
 	public $post_id;
103 103
 
@@ -169,12 +169,12 @@  discard block
 block discarded – undo
169 169
 	public function prevent_maybe_process_form() {
170 170
 
171 171
 		if( ! empty( $_POST ) ) {
172
-	        gravityview()->log->debug( 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', array( 'data' => esc_html( print_r( $_POST, true ) ) ) );
172
+			gravityview()->log->debug( 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', array( 'data' => esc_html( print_r( $_POST, true ) ) ) );
173 173
 		}
174 174
 
175 175
 		if( $this->is_edit_entry_submission() ) {
176 176
 			remove_action( 'wp',  array( 'RGForms', 'maybe_process_form'), 9 );
177
-	        remove_action( 'wp',  array( 'GFForms', 'maybe_process_form'), 9 );
177
+			remove_action( 'wp',  array( 'GFForms', 'maybe_process_form'), 9 );
178 178
 		}
179 179
 	}
180 180
 
@@ -202,14 +202,14 @@  discard block
 block discarded – undo
202 202
 	 * When Edit entry view is requested setup the vars
203 203
 	 */
204 204
 	private function setup_vars() {
205
-        global $post;
205
+		global $post;
206 206
 
207 207
 		$gravityview_view = GravityView_View::getInstance();
208 208
 
209 209
 
210 210
 		$entries = $gravityview_view->getEntries();
211
-	    self::$original_entry = $entries[0];
212
-	    $this->entry = $entries[0];
211
+		self::$original_entry = $entries[0];
212
+		$this->entry = $entries[0];
213 213
 
214 214
 		self::$original_form = $gravityview_view->getForm();
215 215
 		$this->form = $gravityview_view->getForm();
@@ -333,8 +333,8 @@  discard block
 block discarded – undo
333 333
 
334 334
 			GFFormsModel::save_lead( $form, $this->entry );
335 335
 
336
-	        // Delete the values for hidden inputs
337
-	        $this->unset_hidden_field_values();
336
+			// Delete the values for hidden inputs
337
+			$this->unset_hidden_field_values();
338 338
 			
339 339
 			$this->entry['date_created'] = $date_created;
340 340
 
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 			// Perform actions normally performed after updating a lead
348 348
 			$this->after_update();
349 349
 
350
-	        /**
350
+			/**
351 351
 			 * Must be AFTER after_update()!
352 352
 			 * @see https://github.com/gravityview/GravityView/issues/764
353 353
 			 */
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 
356 356
 			/**
357 357
 			 * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry
358
-             * @since 2.1 Added $gv_data parameter
358
+			 * @since 2.1 Added $gv_data parameter
359 359
 			 * @param array $form Gravity Forms form array
360 360
 			 * @param string $entry_id Numeric ID of the entry that was updated
361 361
 			 * @param GravityView_Edit_Entry_Render $this This object
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
 	 * @return void
380 380
 	 */
381 381
 	private function unset_hidden_field_values() {
382
-	    global $wpdb;
382
+		global $wpdb;
383 383
 
384 384
 		/**
385 385
 		 * @filter `gravityview/edit_entry/unset_hidden_field_values` Whether to delete values of fields hidden by conditional logic
@@ -401,27 +401,27 @@  discard block
 block discarded – undo
401 401
 			$current_fields = $wpdb->get_results( $wpdb->prepare( "SELECT id, field_number FROM $lead_detail_table WHERE lead_id=%d", $this->entry['id'] ) );
402 402
 		}
403 403
 
404
-	    foreach ( $this->entry as $input_id => $field_value ) {
404
+		foreach ( $this->entry as $input_id => $field_value ) {
405 405
 
406
-		    $field = RGFormsModel::get_field( $this->form, $input_id );
406
+			$field = RGFormsModel::get_field( $this->form, $input_id );
407 407
 
408
-		    // Reset fields that are hidden
409
-		    // Don't pass $entry as fourth parameter; force using $_POST values to calculate conditional logic
410
-		    if ( GFFormsModel::is_field_hidden( $this->form, $field, array(), NULL ) ) {
408
+			// Reset fields that are hidden
409
+			// Don't pass $entry as fourth parameter; force using $_POST values to calculate conditional logic
410
+			if ( GFFormsModel::is_field_hidden( $this->form, $field, array(), NULL ) ) {
411 411
 
412
-		        // List fields are stored as empty arrays when empty
413
-			    $empty_value = $this->is_field_json_encoded( $field ) ? '[]' : '';
412
+				// List fields are stored as empty arrays when empty
413
+				$empty_value = $this->is_field_json_encoded( $field ) ? '[]' : '';
414 414
 
415
-			    $lead_detail_id = GFFormsModel::get_lead_detail_id( $current_fields, $input_id );
415
+				$lead_detail_id = GFFormsModel::get_lead_detail_id( $current_fields, $input_id );
416 416
 
417
-			    GFFormsModel::update_lead_field_value( $this->form, $this->entry, $field, $lead_detail_id, $input_id, $empty_value );
417
+				GFFormsModel::update_lead_field_value( $this->form, $this->entry, $field, $lead_detail_id, $input_id, $empty_value );
418 418
 
419
-			    // Prevent the $_POST values of hidden fields from being used as default values when rendering the form
419
+				// Prevent the $_POST values of hidden fields from being used as default values when rendering the form
420 420
 				// after submission
421
-			    $post_input_id = 'input_' . str_replace( '.', '_', $input_id );
422
-			    $_POST[ $post_input_id ] = '';
423
-		    }
424
-	    }
421
+				$post_input_id = 'input_' . str_replace( '.', '_', $input_id );
422
+				$_POST[ $post_input_id ] = '';
423
+			}
424
+		}
425 425
 	}
426 426
 
427 427
 	/**
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
 
516 516
 		$form = $this->form;
517 517
 
518
-	    /** @var GF_Field $field */
518
+		/** @var GF_Field $field */
519 519
 		foreach( $form['fields'] as $k => &$field ) {
520 520
 
521 521
 			/**
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 
532 532
 			if( isset( $field->inputs ) && is_array( $field->inputs ) ) {
533 533
 				foreach( $field->inputs as $key => $input ) {
534
-				    $field->inputs[ $key ][ 'id' ] = (string)$input['id'];
534
+					$field->inputs[ $key ][ 'id' ] = (string)$input['id'];
535 535
 				}
536 536
 			}
537 537
 		}
@@ -558,9 +558,9 @@  discard block
 block discarded – undo
558 558
 			foreach ( $this->fields_with_calculation as $field ) {
559 559
 				$inputs = $field->get_entry_inputs();
560 560
 				if ( is_array( $inputs ) ) {
561
-				    foreach ( $inputs as $input ) {
561
+					foreach ( $inputs as $input ) {
562 562
 						GFFormsModel::save_input( $form, $field, $entry, $current_fields, $input['id'] );
563
-				    }
563
+					}
564 564
 				} else {
565 565
 					GFFormsModel::save_input( $form, $field, $entry, $current_fields, $field->id );
566 566
 				}
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
 			$value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'] );
617 617
 
618 618
 			$ary = ! empty( $value ) ? explode( '|:|', $value ) : array();
619
-	        $ary = stripslashes_deep( $ary );
619
+			$ary = stripslashes_deep( $ary );
620 620
 			$img_url = \GV\Utils::get( $ary, 0 );
621 621
 
622 622
 			$img_title       = count( $ary ) > 1 ? $ary[1] : '';
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
 	private function maybe_update_post_fields( $form ) {
690 690
 
691 691
 		if( empty( $this->entry['post_id'] ) ) {
692
-	        gravityview()->log->debug( 'This entry has no post fields. Continuing...' );
692
+			gravityview()->log->debug( 'This entry has no post fields. Continuing...' );
693 693
 			return;
694 694
 		}
695 695
 
@@ -724,51 +724,51 @@  discard block
 block discarded – undo
724 724
 
725 725
 				switch( $field->type ) {
726 726
 
727
-				    case 'post_title':
728
-				        $post_title = $value;
729
-				        if ( \GV\Utils::get( $form, 'postTitleTemplateEnabled' ) ) {
730
-				            $post_title = $this->fill_post_template( $form['postTitleTemplate'], $form, $entry_tmp );
731
-				        }
732
-				        $updated_post->post_title = $post_title;
733
-				        $updated_post->post_name  = $post_title;
734
-				        unset( $post_title );
735
-				        break;
736
-
737
-				    case 'post_content':
738
-				        $post_content = $value;
739
-				        if ( \GV\Utils::get( $form, 'postContentTemplateEnabled' ) ) {
740
-				            $post_content = $this->fill_post_template( $form['postContentTemplate'], $form, $entry_tmp, true );
741
-				        }
742
-				        $updated_post->post_content = $post_content;
743
-				        unset( $post_content );
744
-				        break;
745
-				    case 'post_excerpt':
746
-				        $updated_post->post_excerpt = $value;
747
-				        break;
748
-				    case 'post_tags':
749
-				        wp_set_post_tags( $post_id, $value, false );
750
-				        break;
751
-				    case 'post_category':
752
-				        break;
753
-				    case 'post_custom_field':
727
+					case 'post_title':
728
+						$post_title = $value;
729
+						if ( \GV\Utils::get( $form, 'postTitleTemplateEnabled' ) ) {
730
+							$post_title = $this->fill_post_template( $form['postTitleTemplate'], $form, $entry_tmp );
731
+						}
732
+						$updated_post->post_title = $post_title;
733
+						$updated_post->post_name  = $post_title;
734
+						unset( $post_title );
735
+						break;
736
+
737
+					case 'post_content':
738
+						$post_content = $value;
739
+						if ( \GV\Utils::get( $form, 'postContentTemplateEnabled' ) ) {
740
+							$post_content = $this->fill_post_template( $form['postContentTemplate'], $form, $entry_tmp, true );
741
+						}
742
+						$updated_post->post_content = $post_content;
743
+						unset( $post_content );
744
+						break;
745
+					case 'post_excerpt':
746
+						$updated_post->post_excerpt = $value;
747
+						break;
748
+					case 'post_tags':
749
+						wp_set_post_tags( $post_id, $value, false );
750
+						break;
751
+					case 'post_category':
752
+						break;
753
+					case 'post_custom_field':
754 754
 						if ( is_array( $value ) && ( floatval( $field_id ) !== floatval( $field->id ) ) ) {
755 755
 							$value = $value[ $field_id ];
756 756
 						}
757 757
 
758
-				        if( ! empty( $field->customFieldTemplateEnabled ) ) {
759
-				            $value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true );
760
-				        }
758
+						if( ! empty( $field->customFieldTemplateEnabled ) ) {
759
+							$value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true );
760
+						}
761 761
 
762
-	                    if ( $this->is_field_json_encoded( $field ) && ! is_string( $value ) ) {
763
-		                    $value = wp_json_encode( $value );
764
-	                    }
762
+						if ( $this->is_field_json_encoded( $field ) && ! is_string( $value ) ) {
763
+							$value = wp_json_encode( $value );
764
+						}
765 765
 
766
-				        update_post_meta( $post_id, $field->postCustomFieldName, $value );
767
-				        break;
766
+						update_post_meta( $post_id, $field->postCustomFieldName, $value );
767
+						break;
768 768
 
769
-				    case 'post_image':
770
-				        $value = $this->update_post_image( $form, $field, $field_id, $value, $this->entry, $post_id );
771
-				        break;
769
+					case 'post_image':
770
+						$value = $this->update_post_image( $form, $field, $field_id, $value, $this->entry, $post_id );
771
+						break;
772 772
 
773 773
 				}
774 774
 
@@ -813,20 +813,20 @@  discard block
 block discarded – undo
813 813
 	 */
814 814
 	private function is_field_json_encoded( $field ) {
815 815
 
816
-	    $json_encoded = false;
816
+		$json_encoded = false;
817 817
 
818 818
 		$input_type = RGFormsModel::get_input_type( $field );
819 819
 
820
-	    // Only certain custom field types are supported
821
-	    switch( $input_type ) {
822
-		    case 'fileupload':
823
-		    case 'list':
824
-		    case 'multiselect':
825
-			    $json_encoded = true;
826
-			    break;
827
-	    }
820
+		// Only certain custom field types are supported
821
+		switch( $input_type ) {
822
+			case 'fileupload':
823
+			case 'list':
824
+			case 'multiselect':
825
+				$json_encoded = true;
826
+				break;
827
+		}
828 828
 
829
-	    return $json_encoded;
829
+		return $json_encoded;
830 830
 	}
831 831
 
832 832
 	/**
@@ -916,14 +916,14 @@  discard block
 block discarded – undo
916 916
 			?><h2 class="gv-edit-entry-title">
917 917
 				<span><?php
918 918
 
919
-				    /**
920
-				     * @filter `gravityview_edit_entry_title` Modify the edit entry title
921
-				     * @param string $edit_entry_title Modify the "Edit Entry" title
922
-				     * @param GravityView_Edit_Entry_Render $this This object
923
-				     */
924
-				    $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this );
919
+					/**
920
+					 * @filter `gravityview_edit_entry_title` Modify the edit entry title
921
+					 * @param string $edit_entry_title Modify the "Edit Entry" title
922
+					 * @param GravityView_Edit_Entry_Render $this This object
923
+					 */
924
+					$edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this );
925 925
 
926
-				    echo esc_attr( $edit_entry_title );
926
+					echo esc_attr( $edit_entry_title );
927 927
 			?></span>
928 928
 			</h2>
929 929
 
@@ -1032,7 +1032,7 @@  discard block
 block discarded – undo
1032 1032
 
1033 1033
 		ob_get_clean();
1034 1034
 
1035
-	    remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 );
1035
+		remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 );
1036 1036
 		remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) );
1037 1037
 		remove_filter( 'gform_disable_view_counter', '__return_true' );
1038 1038
 		remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 );
@@ -1086,7 +1086,7 @@  discard block
 block discarded – undo
1086 1086
 
1087 1087
 		// for now we don't support Save and Continue feature.
1088 1088
 		if( ! self::$supports_save_and_continue ) {
1089
-	        unset( $form['save'] );
1089
+			unset( $form['save'] );
1090 1090
 		}
1091 1091
 
1092 1092
 		$form = $this->unselect_default_values( $form );
@@ -1113,30 +1113,30 @@  discard block
 block discarded – undo
1113 1113
 			return $field_content;
1114 1114
 		}
1115 1115
 
1116
-        $message = null;
1116
+		$message = null;
1117 1117
 
1118
-        // First, make sure they have the capability to edit the post.
1119
-        if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) {
1118
+		// First, make sure they have the capability to edit the post.
1119
+		if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) {
1120 1120
 
1121
-            /**
1122
-             * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post
1123
-             * @param string $message The existing "You don't have permission..." text
1124
-             */
1125
-            $message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don&rsquo;t have permission to edit this post.', 'gravityview') );
1121
+			/**
1122
+			 * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post
1123
+			 * @param string $message The existing "You don't have permission..." text
1124
+			 */
1125
+			$message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don&rsquo;t have permission to edit this post.', 'gravityview') );
1126 1126
 
1127
-        } elseif( null === get_post( $this->entry['post_id'] ) ) {
1128
-            /**
1129
-             * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists
1130
-             * @param string $message The existing "This field is not editable; the post no longer exists." text
1131
-             */
1132
-            $message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) );
1133
-        }
1127
+		} elseif( null === get_post( $this->entry['post_id'] ) ) {
1128
+			/**
1129
+			 * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists
1130
+			 * @param string $message The existing "This field is not editable; the post no longer exists." text
1131
+			 */
1132
+			$message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) );
1133
+		}
1134 1134
 
1135
-        if( $message ) {
1136
-            $field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) );
1137
-        }
1135
+		if( $message ) {
1136
+			$field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) );
1137
+		}
1138 1138
 
1139
-        return $field_content;
1139
+		return $field_content;
1140 1140
 	}
1141 1141
 
1142 1142
 	/**
@@ -1164,7 +1164,7 @@  discard block
 block discarded – undo
1164 1164
 			|| ! empty( $field_content )
1165 1165
 			|| in_array( $field->type, array( 'honeypot' ) )
1166 1166
 		) {
1167
-	        return $field_content;
1167
+			return $field_content;
1168 1168
 		}
1169 1169
 
1170 1170
 		// SET SOME FIELD DEFAULTS TO PREVENT ISSUES
@@ -1172,24 +1172,24 @@  discard block
 block discarded – undo
1172 1172
 
1173 1173
 		$field_value = $this->get_field_value( $field );
1174 1174
 
1175
-	    // Prevent any PHP warnings, like undefined index
1176
-	    ob_start();
1175
+		// Prevent any PHP warnings, like undefined index
1176
+		ob_start();
1177 1177
 
1178
-	    $return = null;
1178
+		$return = null;
1179 1179
 
1180 1180
 		/** @var GravityView_Field $gv_field */
1181 1181
 		if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) {
1182 1182
 			$return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field );
1183 1183
 		} else {
1184
-	        $return = $field->get_field_input( $this->form, $field_value, $this->entry );
1185
-	    }
1184
+			$return = $field->get_field_input( $this->form, $field_value, $this->entry );
1185
+		}
1186 1186
 
1187
-	    // If there was output, it's an error
1188
-	    $warnings = ob_get_clean();
1187
+		// If there was output, it's an error
1188
+		$warnings = ob_get_clean();
1189 1189
 
1190
-	    if( !empty( $warnings ) ) {
1191
-		    gravityview()->log->error( '{warning}', array( 'warning' => $warnings, 'data' => $field_value ) );
1192
-	    }
1190
+		if( !empty( $warnings ) ) {
1191
+			gravityview()->log->error( '{warning}', array( 'warning' => $warnings, 'data' => $field_value ) );
1192
+		}
1193 1193
 
1194 1194
 		return $return;
1195 1195
 	}
@@ -1224,8 +1224,8 @@  discard block
 block discarded – undo
1224 1224
 				$input_id = strval( $input['id'] );
1225 1225
 				
1226 1226
 				if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) {
1227
-				    $field_value[ $input_id ] =  'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ];
1228
-				    $allow_pre_populated = false;
1227
+					$field_value[ $input_id ] =  'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ];
1228
+					$allow_pre_populated = false;
1229 1229
 				}
1230 1230
 
1231 1231
 			}
@@ -1249,7 +1249,7 @@  discard block
 block discarded – undo
1249 1249
 			if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) {
1250 1250
 				$categories = array();
1251 1251
 				foreach ( explode( ',', $field_value ) as $cat_string ) {
1252
-				    $categories[] = GFCommon::format_post_category( $cat_string, true );
1252
+					$categories[] = GFCommon::format_post_category( $cat_string, true );
1253 1253
 				}
1254 1254
 				$field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories );
1255 1255
 			}
@@ -1259,25 +1259,25 @@  discard block
 block discarded – undo
1259 1259
 		// if value is empty get the default value if defined
1260 1260
 		$field_value = $field->get_value_default_if_empty( $field_value );
1261 1261
 
1262
-	    /**
1263
-	     * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed
1264
-	     * @since 1.11
1265
-	     * @since 1.20 Added third param
1266
-	     * @param mixed $field_value field value used to populate the input
1267
-	     * @param object $field Gravity Forms field object ( Class GF_Field )
1268
-	     * @param GravityView_Edit_Entry_Render $this Current object
1269
-	     */
1270
-	    $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field, $this );
1271
-
1272
-	    /**
1273
-	     * @filter `gravityview/edit_entry/field_value_{field_type}` Change the value of an Edit Entry field for a specific field type
1274
-	     * @since 1.17
1275
-	     * @since 1.20 Added third param
1276
-	     * @param mixed $field_value field value used to populate the input
1277
-	     * @param GF_Field $field Gravity Forms field object
1278
-	     * @param GravityView_Edit_Entry_Render $this Current object
1279
-	     */
1280
-	    $field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type , $field_value, $field, $this );
1262
+		/**
1263
+		 * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed
1264
+		 * @since 1.11
1265
+		 * @since 1.20 Added third param
1266
+		 * @param mixed $field_value field value used to populate the input
1267
+		 * @param object $field Gravity Forms field object ( Class GF_Field )
1268
+		 * @param GravityView_Edit_Entry_Render $this Current object
1269
+		 */
1270
+		$field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field, $this );
1271
+
1272
+		/**
1273
+		 * @filter `gravityview/edit_entry/field_value_{field_type}` Change the value of an Edit Entry field for a specific field type
1274
+		 * @since 1.17
1275
+		 * @since 1.20 Added third param
1276
+		 * @param mixed $field_value field value used to populate the input
1277
+		 * @param GF_Field $field Gravity Forms field object
1278
+		 * @param GravityView_Edit_Entry_Render $this Current object
1279
+		 */
1280
+		$field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type , $field_value, $field, $this );
1281 1281
 
1282 1282
 		return $field_value;
1283 1283
 	}
@@ -1304,7 +1304,7 @@  discard block
 block discarded – undo
1304 1304
 			// This is because we're doing admin form pretending to be front-end, so Gravity Forms
1305 1305
 			// expects certain field array items to be set.
1306 1306
 			foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) {
1307
-	            $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL;
1307
+				$field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL;
1308 1308
 			}
1309 1309
 
1310 1310
 			switch( RGFormsModel::get_input_type( $field ) ) {
@@ -1318,61 +1318,61 @@  discard block
 block discarded – undo
1318 1318
 				 */
1319 1319
 				case 'fileupload':
1320 1320
 
1321
-				    // Set the previous value
1322
-				    $entry = $this->get_entry();
1321
+					// Set the previous value
1322
+					$entry = $this->get_entry();
1323 1323
 
1324
-				    $input_name = 'input_'.$field->id;
1325
-				    $form_id = $form['id'];
1324
+					$input_name = 'input_'.$field->id;
1325
+					$form_id = $form['id'];
1326 1326
 
1327
-				    $value = NULL;
1327
+					$value = NULL;
1328 1328
 
1329
-				    // Use the previous entry value as the default.
1330
-				    if( isset( $entry[ $field->id ] ) ) {
1331
-				        $value = $entry[ $field->id ];
1332
-				    }
1329
+					// Use the previous entry value as the default.
1330
+					if( isset( $entry[ $field->id ] ) ) {
1331
+						$value = $entry[ $field->id ];
1332
+					}
1333 1333
 
1334
-				    // If this is a single upload file
1335
-				    if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) {
1336
-				        $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] );
1337
-				        $value = $file_path['url'];
1334
+					// If this is a single upload file
1335
+					if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) {
1336
+						$file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] );
1337
+						$value = $file_path['url'];
1338 1338
 
1339
-				    } else {
1339
+					} else {
1340 1340
 
1341
-				        // Fix PHP warning on line 1498 of form_display.php for post_image fields
1342
-				        // Fix PHP Notice:  Undefined index:  size in form_display.php on line 1511
1343
-				        $_FILES[ $input_name ] = array('name' => '', 'size' => '' );
1341
+						// Fix PHP warning on line 1498 of form_display.php for post_image fields
1342
+						// Fix PHP Notice:  Undefined index:  size in form_display.php on line 1511
1343
+						$_FILES[ $input_name ] = array('name' => '', 'size' => '' );
1344 1344
 
1345
-				    }
1345
+					}
1346 1346
 
1347
-				    if ( \GV\Utils::get( $field, "multipleFiles" ) ) {
1347
+					if ( \GV\Utils::get( $field, "multipleFiles" ) ) {
1348 1348
 
1349
-				        // If there are fresh uploads, process and merge them.
1350
-				        // Otherwise, use the passed values, which should be json-encoded array of URLs
1351
-				        if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) {
1352
-				            $value = empty( $value ) ? '[]' : $value;
1353
-				            $value = stripslashes_deep( $value );
1354
-				            $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array());
1355
-				        }
1349
+						// If there are fresh uploads, process and merge them.
1350
+						// Otherwise, use the passed values, which should be json-encoded array of URLs
1351
+						if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) {
1352
+							$value = empty( $value ) ? '[]' : $value;
1353
+							$value = stripslashes_deep( $value );
1354
+							$value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array());
1355
+						}
1356 1356
 
1357
-				    } else {
1357
+					} else {
1358 1358
 
1359
-				        // A file already exists when editing an entry
1360
-				        // We set this to solve issue when file upload fields are required.
1361
-				        GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value;
1359
+						// A file already exists when editing an entry
1360
+						// We set this to solve issue when file upload fields are required.
1361
+						GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value;
1362 1362
 
1363
-				    }
1363
+					}
1364 1364
 
1365
-				    $this->entry[ $input_name ] = $value;
1366
-				    $_POST[ $input_name ] = $value;
1365
+					$this->entry[ $input_name ] = $value;
1366
+					$_POST[ $input_name ] = $value;
1367 1367
 
1368
-				    break;
1368
+					break;
1369 1369
 
1370 1370
 				case 'number':
1371
-				    // Fix "undefined index" issue at line 1286 in form_display.php
1372
-				    if( !isset( $_POST['input_'.$field->id ] ) ) {
1373
-				        $_POST['input_'.$field->id ] = NULL;
1374
-				    }
1375
-				    break;
1371
+					// Fix "undefined index" issue at line 1286 in form_display.php
1372
+					if( !isset( $_POST['input_'.$field->id ] ) ) {
1373
+						$_POST['input_'.$field->id ] = NULL;
1374
+					}
1375
+					break;
1376 1376
 			}
1377 1377
 
1378 1378
 		}
@@ -1457,42 +1457,42 @@  discard block
 block discarded – undo
1457 1457
 				case 'fileupload' :
1458 1458
 				case 'post_image':
1459 1459
 
1460
-				    // in case nothing is uploaded but there are already files saved
1461
-				    if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) {
1462
-				        $field->failed_validation = false;
1463
-				        unset( $field->validation_message );
1464
-				    }
1460
+					// in case nothing is uploaded but there are already files saved
1461
+					if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) {
1462
+						$field->failed_validation = false;
1463
+						unset( $field->validation_message );
1464
+					}
1465 1465
 
1466
-				    // validate if multi file upload reached max number of files [maxFiles] => 2
1467
-				    if( \GV\Utils::get( $field, 'maxFiles') && \GV\Utils::get( $field, 'multipleFiles') ) {
1466
+					// validate if multi file upload reached max number of files [maxFiles] => 2
1467
+					if( \GV\Utils::get( $field, 'maxFiles') && \GV\Utils::get( $field, 'multipleFiles') ) {
1468 1468
 
1469
-				        $input_name = 'input_' . $field->id;
1470
-				        //uploaded
1471
-				        $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array();
1469
+						$input_name = 'input_' . $field->id;
1470
+						//uploaded
1471
+						$file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array();
1472 1472
 
1473
-				        //existent
1474
-				        $entry = $this->get_entry();
1475
-				        $value = NULL;
1476
-				        if( isset( $entry[ $field->id ] ) ) {
1477
-				            $value = json_decode( $entry[ $field->id ], true );
1478
-				        }
1473
+						//existent
1474
+						$entry = $this->get_entry();
1475
+						$value = NULL;
1476
+						if( isset( $entry[ $field->id ] ) ) {
1477
+							$value = json_decode( $entry[ $field->id ], true );
1478
+						}
1479 1479
 
1480
-				        // count uploaded files and existent entry files
1481
-				        $count_files = count( $file_names ) + count( $value );
1480
+						// count uploaded files and existent entry files
1481
+						$count_files = count( $file_names ) + count( $value );
1482 1482
 
1483
-				        if( $count_files > $field->maxFiles ) {
1484
-				            $field->validation_message = __( 'Maximum number of files reached', 'gravityview' );
1485
-				            $field->failed_validation = 1;
1486
-				            $gv_valid = false;
1483
+						if( $count_files > $field->maxFiles ) {
1484
+							$field->validation_message = __( 'Maximum number of files reached', 'gravityview' );
1485
+							$field->failed_validation = 1;
1486
+							$gv_valid = false;
1487 1487
 
1488
-				            // in case of error make sure the newest upload files are removed from the upload input
1489
-				            GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null;
1490
-				        }
1488
+							// in case of error make sure the newest upload files are removed from the upload input
1489
+							GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null;
1490
+						}
1491 1491
 
1492
-				    }
1492
+					}
1493 1493
 
1494 1494
 
1495
-				    break;
1495
+					break;
1496 1496
 
1497 1497
 			}
1498 1498
 
@@ -1503,47 +1503,47 @@  discard block
 block discarded – undo
1503 1503
 
1504 1504
 				switch ( $field_type ) {
1505 1505
 
1506
-				    // Captchas don't need to be re-entered.
1507
-				    case 'captcha':
1506
+					// Captchas don't need to be re-entered.
1507
+					case 'captcha':
1508 1508
 
1509
-				        // Post Image fields aren't editable, so we un-fail them.
1510
-				    case 'post_image':
1511
-				        $field->failed_validation = false;
1512
-				        unset( $field->validation_message );
1513
-				        break;
1509
+						// Post Image fields aren't editable, so we un-fail them.
1510
+					case 'post_image':
1511
+						$field->failed_validation = false;
1512
+						unset( $field->validation_message );
1513
+						break;
1514 1514
 
1515 1515
 				}
1516 1516
 
1517 1517
 				// You can't continue inside a switch, so we do it after.
1518 1518
 				if( empty( $field->failed_validation ) ) {
1519
-				    continue;
1519
+					continue;
1520 1520
 				}
1521 1521
 
1522 1522
 				// checks if the No Duplicates option is not validating entry against itself, since
1523 1523
 				// we're editing a stored entry, it would also assume it's a duplicate.
1524 1524
 				if( !empty( $field->noDuplicates ) ) {
1525 1525
 
1526
-				    $entry = $this->get_entry();
1526
+					$entry = $this->get_entry();
1527 1527
 
1528
-				    // If the value of the entry is the same as the stored value
1529
-				    // Then we can assume it's not a duplicate, it's the same.
1530
-				    if( !empty( $entry ) && $value == $entry[ $field->id ] ) {
1531
-				        //if value submitted was not changed, then don't validate
1532
-				        $field->failed_validation = false;
1528
+					// If the value of the entry is the same as the stored value
1529
+					// Then we can assume it's not a duplicate, it's the same.
1530
+					if( !empty( $entry ) && $value == $entry[ $field->id ] ) {
1531
+						//if value submitted was not changed, then don't validate
1532
+						$field->failed_validation = false;
1533 1533
 
1534
-				        unset( $field->validation_message );
1534
+						unset( $field->validation_message );
1535 1535
 
1536
-				        gravityview()->log->debug( 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', array( 'data' => $entry ) );
1536
+						gravityview()->log->debug( 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', array( 'data' => $entry ) );
1537 1537
 
1538
-				        continue;
1539
-				    }
1538
+						continue;
1539
+					}
1540 1540
 				}
1541 1541
 
1542 1542
 				// if here then probably we are facing the validation 'At least one field must be filled out'
1543 1543
 				if( GFFormDisplay::is_empty( $field, $this->form_id  ) && empty( $field->isRequired ) ) {
1544
-				    unset( $field->validation_message );
1545
-	                $field->validation_message = false;
1546
-				    continue;
1544
+					unset( $field->validation_message );
1545
+					$field->validation_message = false;
1546
+					continue;
1547 1547
 				}
1548 1548
 
1549 1549
 				$gv_valid = false;
@@ -1607,8 +1607,8 @@  discard block
 block discarded – undo
1607 1607
 		// Hide fields depending on admin settings
1608 1608
 		$fields = $this->filter_fields( $form['fields'], $edit_fields );
1609 1609
 
1610
-	    // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't.
1611
-	    $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id );
1610
+		// If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't.
1611
+		$fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id );
1612 1612
 
1613 1613
 		/**
1614 1614
 		 * @filter `gravityview/edit_entry/form_fields` Modify the fields displayed in Edit Entry form
@@ -1668,11 +1668,11 @@  discard block
 block discarded – undo
1668 1668
 		// The edit tab has been configured, so we loop through to configured settings
1669 1669
 		foreach ( $configured_fields as $configured_field ) {
1670 1670
 
1671
-	        /** @var GF_Field $field */
1672
-	        foreach ( $fields as $field ) {
1671
+			/** @var GF_Field $field */
1672
+			foreach ( $fields as $field ) {
1673 1673
 				if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) {
1674
-				    $edit_fields[] = $this->merge_field_properties( $field, $configured_field );
1675
-				    break;
1674
+					$edit_fields[] = $this->merge_field_properties( $field, $configured_field );
1675
+					break;
1676 1676
 				}
1677 1677
 
1678 1678
 			}
@@ -1728,28 +1728,28 @@  discard block
 block discarded – undo
1728 1728
 	 */
1729 1729
 	private function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) {
1730 1730
 
1731
-	    /**
1731
+		/**
1732 1732
 		 * @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
1733
-	     * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators.
1734
-	     * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions
1735
-	     * @since 1.9.1
1736
-	     * @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.
1737
-	     * @param array $form GF Form array
1738
-	     * @param int $view_id View ID
1739
-	     */
1740
-	    $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id );
1741
-
1742
-	    if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) {
1733
+		 * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators.
1734
+		 * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions
1735
+		 * @since 1.9.1
1736
+		 * @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.
1737
+		 * @param array $form GF Form array
1738
+		 * @param int $view_id View ID
1739
+		 */
1740
+		$use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id );
1741
+
1742
+		if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) {
1743 1743
 			foreach( $fields as $k => $field ) {
1744 1744
 				if( $field->adminOnly ) {
1745
-				    unset( $fields[ $k ] );
1745
+					unset( $fields[ $k ] );
1746 1746
 				}
1747 1747
 			}
1748 1748
 			return array_values( $fields );
1749 1749
 		}
1750 1750
 
1751
-	    foreach( $fields as &$field ) {
1752
-		    $field->adminOnly = false;
1751
+		foreach( $fields as &$field ) {
1752
+			$field->adminOnly = false;
1753 1753
 		}
1754 1754
 
1755 1755
 		return $fields;
@@ -1769,13 +1769,13 @@  discard block
 block discarded – undo
1769 1769
 	 */
1770 1770
 	private function unselect_default_values( $form ) {
1771 1771
 
1772
-	    foreach ( $form['fields'] as &$field ) {
1772
+		foreach ( $form['fields'] as &$field ) {
1773 1773
 
1774 1774
 			if ( empty( $field->choices ) ) {
1775
-                continue;
1775
+				continue;
1776 1776
 			}
1777 1777
 
1778
-            foreach ( $field->choices as &$choice ) {
1778
+			foreach ( $field->choices as &$choice ) {
1779 1779
 				if ( \GV\Utils::get( $choice, 'isSelected' ) ) {
1780 1780
 					$choice['isSelected'] = false;
1781 1781
 				}
@@ -1812,36 +1812,36 @@  discard block
 block discarded – undo
1812 1812
 
1813 1813
 			if( 'checkbox' === $field->type ) {
1814 1814
 				foreach ( $field->get_entry_inputs() as $key => $input ) {
1815
-				    $input_id = $input['id'];
1816
-				    $choice = $field->choices[ $key ];
1817
-				    $value = \GV\Utils::get( $this->entry, $input_id );
1818
-				    $match = RGFormsModel::choice_value_match( $field, $choice, $value );
1819
-				    if( $match ) {
1820
-				        $field->choices[ $key ]['isSelected'] = true;
1821
-				    }
1815
+					$input_id = $input['id'];
1816
+					$choice = $field->choices[ $key ];
1817
+					$value = \GV\Utils::get( $this->entry, $input_id );
1818
+					$match = RGFormsModel::choice_value_match( $field, $choice, $value );
1819
+					if( $match ) {
1820
+						$field->choices[ $key ]['isSelected'] = true;
1821
+					}
1822 1822
 				}
1823 1823
 			} else {
1824 1824
 
1825 1825
 				// We need to run through each field to set the default values
1826 1826
 				foreach ( $this->entry as $field_id => $field_value ) {
1827 1827
 
1828
-				    if( floatval( $field_id ) === floatval( $field->id ) ) {
1828
+					if( floatval( $field_id ) === floatval( $field->id ) ) {
1829 1829
 
1830
-				        if( 'list' === $field->type ) {
1831
-				            $list_rows = maybe_unserialize( $field_value );
1830
+						if( 'list' === $field->type ) {
1831
+							$list_rows = maybe_unserialize( $field_value );
1832 1832
 
1833
-				            $list_field_value = array();
1834
-				            foreach ( (array) $list_rows as $row ) {
1835
-				                foreach ( (array) $row as $column ) {
1836
-				                    $list_field_value[] = $column;
1837
-				                }
1838
-				            }
1833
+							$list_field_value = array();
1834
+							foreach ( (array) $list_rows as $row ) {
1835
+								foreach ( (array) $row as $column ) {
1836
+									$list_field_value[] = $column;
1837
+								}
1838
+							}
1839 1839
 
1840
-				            $field->defaultValue = serialize( $list_field_value );
1841
-				        } else {
1842
-				            $field->defaultValue = $field_value;
1843
-				        }
1844
-				    }
1840
+							$field->defaultValue = serialize( $list_field_value );
1841
+						} else {
1842
+							$field->defaultValue = $field_value;
1843
+						}
1844
+					}
1845 1845
 				}
1846 1846
 			}
1847 1847
 		}
@@ -1898,7 +1898,7 @@  discard block
 block discarded – undo
1898 1898
 			return $has_conditional_logic;
1899 1899
 		}
1900 1900
 
1901
-	    /** @see GravityView_Edit_Entry_Render::filter_conditional_logic for filter documentation */
1901
+		/** @see GravityView_Edit_Entry_Render::filter_conditional_logic for filter documentation */
1902 1902
 		return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form );
1903 1903
 	}
1904 1904
 
@@ -1965,14 +1965,14 @@  discard block
 block discarded – undo
1965 1965
 
1966 1966
 		if( $echo && $error !== true ) {
1967 1967
 
1968
-	        $error = esc_html( $error );
1968
+			$error = esc_html( $error );
1969 1969
 
1970
-	        /**
1971
-	         * @since 1.9
1972
-	         */
1973
-	        if ( ! empty( $this->entry ) ) {
1974
-		        $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;" ) );
1975
-	        }
1970
+			/**
1971
+			 * @since 1.9
1972
+			 */
1973
+			if ( ! empty( $this->entry ) ) {
1974
+				$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;" ) );
1975
+			}
1976 1976
 
1977 1977
 			echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error');
1978 1978
 		}
Please login to merge, or discard this patch.