GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-edit-entry-render.php
Go to the documentation of this file.
1 <?php
2 /**
3  * GravityView Edit Entry - render frontend
4  *
5  * @package GravityView
6  * @license GPL2+
7  * @author GravityView <[email protected]>
8  * @link http://gravityview.co
9  * @copyright Copyright 2014, Katz Web Services, Inc.
10  */
11 
12 if ( ! defined( 'WPINC' ) ) {
13  die;
14 }
15 
17 
18  /**
19  * @var GravityView_Edit_Entry
20  */
21  protected $loader;
22 
23  /**
24  * @var string $nonce_key String used to generate unique nonce for the entry/form/view combination. Allows access to edit page.
25  */
26  static $nonce_key;
27 
28  /**
29  * @since 1.9
30  * @var string $nonce_field String used for check valid edit entry form submission. Allows saving edit form values.
31  */
32  private static $nonce_field = 'is_gv_edit_entry';
33 
34  /**
35  * @since 1.9
36  * @var bool Whether to allow save and continue functionality
37  */
38  private static $supports_save_and_continue = false;
39 
40  /**
41  * Gravity Forms entry array
42  *
43  * @var array
44  */
45  public $entry;
46 
47  /**
48  * The View.
49  *
50  * @var \GV\View.
51  * @since develop
52  */
53  public $view;
54 
55  /**
56  * Gravity Forms entry array (it won't get changed during this class lifecycle)
57  * @since 1.17.2
58  * @var array
59  */
60  private static $original_entry = array();
61 
62  /**
63  * Gravity Forms form array (GravityView modifies the content through this class lifecycle)
64  *
65  * @var array
66  */
67  public $form;
68 
69  /**
70  * Gravity Forms form array (it won't get changed during this class lifecycle)
71  * @since 1.16.2.1
72  * @var array
73  */
74  private static $original_form;
75 
76  /**
77  * Gravity Forms form array after the form validation process
78  * @since 1.13
79  * @var array
80  */
81  public $form_after_validation = null;
82 
83  /**
84  * Hold an array of GF field objects that have calculation rules
85  * @var array
86  */
87  public $fields_with_calculation = array();
88 
89  /**
90  * Gravity Forms form id
91  *
92  * @var int
93  */
94  public $form_id;
95 
96  /**
97  * ID of the current view
98  *
99  * @var int
100  */
101  public $view_id;
102 
103  /**
104  * ID of the current post. May also be ID of the current View.
105  *
106  * @since 2.0.13
107  *
108  * @var int
109  */
110  public $post_id;
111 
112  /**
113  * Updated entry is valid (GF Validation object)
114  *
115  * @var array
116  */
117  public $is_valid = NULL;
118 
119  /**
120  * Internal page button states.
121  *
122  * @var bool
123  *
124  * @since develop
125  */
130 
132  $this->loader = $loader;
133  }
134 
135  function load() {
136 
137  /** @define "GRAVITYVIEW_DIR" "../../../" */
138  include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' );
139 
140  // Don't display an embedded form when editing an entry
141  add_action( 'wp_head', array( $this, 'prevent_render_form' ) );
142  add_action( 'wp_footer', array( $this, 'prevent_render_form' ) );
143 
144  // Stop Gravity Forms processing what is ours!
145  add_action( 'wp', array( $this, 'prevent_maybe_process_form' ), 8 );
146  add_action( 'admin_init', array( $this, 'prevent_maybe_process_form' ), 8 );
147 
148  add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') );
149 
150  add_action( 'gravityview_edit_entry', array( $this, 'init' ), 10, 4 );
151 
152  // Disable conditional logic if needed (since 1.9)
153  add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 );
154 
155  // Make sure GF doesn't validate max files (since 1.9)
156  add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 );
157 
158  // Add fields expected by GFFormDisplay::validate()
159  add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') );
160 
161  // Fix multiselect value for GF 2.2
162  add_filter( 'gravityview/edit_entry/field_value_multiselect', array( $this, 'fix_multiselect_value_serialization' ), 10, 3 );
163  }
164 
165  /**
166  * Don't show any forms embedded on a page when GravityView is in Edit Entry mode
167  *
168  * Adds a `__return_empty_string` filter on the Gravity Forms shortcode on the `wp_head` action
169  * And then removes it on the `wp_footer` action
170  *
171  * @since 1.16.1
172  *
173  * @return void
174  */
175  public function prevent_render_form() {
176  if( $this->is_edit_entry() ) {
177  if( 'wp_head' === current_filter() ) {
178  add_filter( 'gform_shortcode_form', '__return_empty_string' );
179  } else {
180  remove_filter( 'gform_shortcode_form', '__return_empty_string' );
181  }
182  }
183  }
184 
185  /**
186  * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms
187  * backend form, we need to prevent them from saving twice.
188  * @return void
189  */
190  public function prevent_maybe_process_form() {
191 
192  if( ! $this->is_edit_entry_submission() ) {
193  return;
194  }
195 
196  gravityview()->log->debug( 'GravityView_Edit_Entry[prevent_maybe_process_form] Removing GFForms::maybe_process_form() action.' );
197 
198  remove_action( 'wp', array( 'RGForms', 'maybe_process_form'), 9 );
199  remove_action( 'wp', array( 'GFForms', 'maybe_process_form'), 9 );
200 
201  remove_action( 'admin_init', array( 'GFForms', 'maybe_process_form'), 9 );
202  remove_action( 'admin_init', array( 'RGForms', 'maybe_process_form'), 9 );
203  }
204 
205  /**
206  * Is the current page an Edit Entry page?
207  * @return boolean
208  */
209  public function is_edit_entry() {
210 
211  $is_edit_entry =
212  ( GravityView_frontend::is_single_entry() || gravityview()->request->is_entry() )
213  && ( ! empty( $_GET['edit'] ) );
214 
215  return ( $is_edit_entry || $this->is_edit_entry_submission() );
216  }
217 
218  /**
219  * Is the current page an Edit Entry page?
220  * @since 1.9
221  * @return boolean
222  */
223  public function is_edit_entry_submission() {
224  return !empty( $_POST[ self::$nonce_field ] );
225  }
226 
227  /**
228  * When Edit entry view is requested, set up key class variables
229  *
230  * @since 2.14.6 Added $view and $entry params
231  *
232  * @param \GV\View $view The View.
233  * @param \GV\Entry $entry The Entry.
234  *
235  * @return void
236  */
237  private function setup_vars( $view, $entry ) {
238  global $post;
239 
240  if ( $entry ) {
241  self::$original_entry = $entry->as_entry();
242  $this->entry = $entry->as_entry();
243  } else {
245  $entries = $gravityview_view->getEntries();
246  self::$original_entry = $entries[0];
247  $this->entry = $entries[0];
248  }
249 
250  self::$original_form = GFAPI::get_form( $this->entry['form_id'] );
251  $this->form = self::$original_form;
252 
253  $this->form_id = $this->entry['form_id'];
254 
255  $this->view_id = $view ? $view->ID : $gravityview_view->getViewId();
256 
257  $this->view = $view;
258 
259  $this->post_id = \GV\Utils::get( $post, 'ID', null );
260 
261  self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] );
262  }
263 
264  /**
265  * Load required files and trigger edit flow
266  *
267  * Run when the is_edit_entry returns true.
268  *
269  * @param \GravityView_View_Data $gv_data GravityView Data object
270  * @param \GV\Entry $entry The Entry.
271  * @param \GV\View $view The View.
272  * @param \GV\Request $request The Request.
273  *
274  * @since develop Added $entry, $view, $request adhocs.
275  *
276  * @return void
277  */
278  public function init( $gv_data = null, $entry = null, $view = null, $request = null ) {
279 
280  require_once( GFCommon::get_base_path() . '/form_display.php' );
281  require_once( GFCommon::get_base_path() . '/entry_detail.php' );
282 
283  $this->setup_vars( $view, $entry );
284 
285  if ( ! $gv_data ) {
287  }
288 
289  if ( $view && ! $gv_data->views->count() ) {
290  $gv_data->views->add( $view );
291  }
292 
293  // Multiple Views embedded, don't proceed if nonce fails
294  if ( $gv_data->has_multiple_views() && ! $this->verify_nonce() ) {
295  gravityview()->log->error( 'Nonce validation failed for the Edit Entry request; returning' );
296  return;
297  }
298 
299  // Sorry, you're not allowed here.
300  if ( false === $this->user_can_edit_entry( true ) ) {
301  gravityview()->log->error( 'User is not allowed to edit this entry; returning', array( 'data' => $this->entry ) );
302  return;
303  }
304 
305  $this->print_scripts();
306 
307  $this->process_save( $gv_data );
308 
309  $this->edit_entry_form();
310 
311  }
312 
313 
314  /**
315  * Force Gravity Forms to output scripts as if it were in the admin
316  * @return void
317  */
318  private function print_scripts() {
320 
321  wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) );
322 
323  GFFormDisplay::enqueue_form_scripts( $this->form ? $this->form : $gravityview_view->getForm(), false );
324 
325  wp_localize_script( 'gravityview-fe-view', 'gvGlobals', array( 'cookiepath' => COOKIEPATH ) );
326 
327  wp_enqueue_script( 'sack'); // Sack is required for images.
328  wp_enqueue_script( 'gform_gravityforms');
329  wp_enqueue_script( 'gravityview-fe-view');
330 
331  // File download/delete icons
332  wp_enqueue_style( 'gform_admin_icons' );
333  }
334 
335 
336  /**
337  * Process edit entry form save
338  *
339  * @param GravityView_View_Data $gv_data The View data.
340  */
341  private function process_save( $gv_data ) {
342 
343  if ( empty( $_POST ) || ! isset( $_POST['lid'] ) ) {
344  return;
345  }
346 
347  // Make sure the entry, view, and form IDs are all correct
348  $valid = $this->verify_nonce();
349 
350  if ( !$valid ) {
351  gravityview()->log->error( 'Nonce validation failed.' );
352  return;
353  }
354 
355  if ( $this->entry['id'] !== $_POST['lid'] ) {
356  gravityview()->log->error( 'Entry ID did not match posted entry ID.' );
357  return;
358  }
359 
360  gravityview()->log->debug( '$_POSTed data (sanitized): ', array( 'data' => esc_html( print_r( $_POST, true ) ) ) );
361 
362  $this->process_save_process_files( $this->form_id );
363 
364  $this->validate();
365 
366  if( $this->is_valid ) {
367 
368  gravityview()->log->debug( 'Submission is valid.' );
369 
370  /**
371  * @hack This step is needed to unset the adminOnly from form fields, to add the calculation fields
372  */
373  $form = $this->form_prepare_for_save();
374 
375  /**
376  * @hack to avoid the capability validation of the method save_lead for GF 1.9+
377  */
378  unset( $_GET['page'] );
379 
380  add_filter( 'gform_use_post_value_for_conditional_logic_save_entry', '__return_true' );
381 
382  /**
383  * @action `gravityview/edit_entry/before_update` Perform an action before the entry has been updated using Edit Entry
384  * @since 2.1
385  * @param array $form Gravity Forms form array
386  * @param string $entry_id Numeric ID of the entry that is being updated
387  * @param GravityView_Edit_Entry_Render $this This object
388  * @param GravityView_View_Data $gv_data The View data
389  */
390  do_action( 'gravityview/edit_entry/before_update', $form, $this->entry['id'], $this, $gv_data );
391 
392  GFFormsModel::save_lead( $form, $this->entry );
393 
394  // Delete the values for hidden inputs
395  $this->unset_hidden_field_values();
396 
397  // Process calculation fields
398  $this->update_calculation_fields();
399 
400  // Handle hidden approval fields (or their absense)
401  $this->preset_approval_fields();
402 
403  // Perform actions normally performed after updating a lead
404  $this->after_update();
405 
406  /**
407  * Must be AFTER after_update()!
408  * @see https://github.com/gravityview/GravityView/issues/764
409  */
411 
412  /**
413  * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry
414  * @since 2.1 Added $gv_data parameter
415  * @param array $form Gravity Forms form array
416  * @param string $entry_id Numeric ID of the entry that was updated
417  * @param GravityView_Edit_Entry_Render $this This object
418  * @param GravityView_View_Data $gv_data The View data
419  */
420  do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'], $this, $gv_data );
421 
422  } else {
423  gravityview()->log->error( 'Submission is NOT valid.', array( 'entry' => $this->entry ) );
424  }
425 
426  } // process_save
427 
428  /**
429  * Delete the value of fields hidden by conditional logic when the entry is edited
430  *
431  * @uses GFFormsModel::update_lead_field_value()
432  *
433  * @since 1.17.4
434  *
435  * @return void
436  */
437  private function unset_hidden_field_values() {
438  global $wpdb;
439 
440  /**
441  * @filter `gravityview/edit_entry/unset_hidden_field_values` Whether to delete values of fields hidden by conditional logic
442  * @since 1.22.2
443  * @param bool $unset_hidden_field_values Default: true
444  * @param GravityView_Edit_Entry_Render $this This object
445  */
446  $unset_hidden_field_values = apply_filters( 'gravityview/edit_entry/unset_hidden_field_values', true, $this );
447 
448  $this->unset_hidden_calculations = array();
449 
450  if ( ! $unset_hidden_field_values ) {
451  return;
452  }
453 
454  if ( version_compare( GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=' ) && method_exists( 'GFFormsModel', 'get_entry_meta_table_name' ) ) {
455  $entry_meta_table = GFFormsModel::get_entry_meta_table_name();
456  $current_fields = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $entry_meta_table WHERE entry_id=%d", $this->entry['id'] ) );
457  } else {
458  $lead_detail_table = GFFormsModel::get_lead_details_table_name();
459  $current_fields = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $lead_detail_table WHERE lead_id=%d", $this->entry['id'] ) );
460  }
461 
462  foreach ( $this->entry as $input_id => $field_value ) {
463 
464  if ( ! is_numeric( $input_id ) ) {
465  continue;
466  }
467 
468  if ( ! $field = RGFormsModel::get_field( $this->form, $input_id ) ) {
469  continue;
470  }
471 
472  // Reset fields that are or would be hidden
473  if ( GFFormsModel::is_field_hidden( $this->form, $field, array(), $this->entry ) ) {
474 
475  $empty_value = $field->get_value_save_entry(
476  is_array( $field->get_entry_inputs() ) ? array() : '',
477  $this->form, '', $this->entry['id'], $this->entry
478  );
479 
480  if ( $field->has_calculation() ) {
481  $this->unset_hidden_calculations[] = $field->id; // Unset
482  $empty_value = '';
483  }
484 
485  $lead_detail_id = GFFormsModel::get_lead_detail_id( $current_fields, $input_id );
486 
487  GFFormsModel::update_lead_field_value( $this->form, $this->entry, $field, $lead_detail_id, $input_id, $empty_value );
488 
489  // Prevent the $_POST values of hidden fields from being used as default values when rendering the form
490  // after submission
491  $post_input_id = 'input_' . str_replace( '.', '_', $input_id );
492  $_POST[ $post_input_id ] = '';
493  }
494  }
495  }
496 
497  /**
498  * Leverage `gravityview/approve_entries/update_unapproved_meta` to prevent
499  * the missing/empty approval field to affect is_approved meta at all.
500  *
501  * Called before the Gravity Forms after_update triggers.
502  *
503  * @since 2.5
504  *
505  * @return void
506  */
507  private function preset_approval_fields() {
508  $has_approved_field = false;
509 
510  foreach ( self::$original_form['fields'] as $field ) {
511  if ( $field->gravityview_approved ) {
512  $has_approved_field = true;
513  break;
514  }
515  }
516 
517  if ( ! $has_approved_field ) {
518  return;
519  }
520 
521  $is_field_hidden = true;
522 
523  foreach ( $this->form['fields'] as $field ) {
524  if ( $field->gravityview_approved ) {
525  $is_field_hidden = false;
526  break;
527  }
528  }
529 
530  if ( ! $is_field_hidden ) {
531  return;
532  }
533 
534  add_filter( 'gravityview/approve_entries/update_unapproved_meta', array( $this, 'prevent_update_unapproved_meta' ), 9, 3 );
535  }
536 
537  /**
538  * Done once from self::preset_approval_fields
539  *
540  * @since 2.5
541  *
542  * @return string UNAPPROVED unless something else is inside the entry.
543  */
545 
546  remove_filter( 'gravityview/approve_entries/update_unapproved_meta', array( $this, 'prevent_update_unapproved_meta' ), 9 );
547 
548  if ( ! $value = gform_get_meta( $entry['id'], 'is_approved' ) ) {
549 
551 
552  $value = apply_filters( 'gravityview/approve_entries/after_submission/default_status', $value );
553  }
554 
555  return $value;
556  }
557 
558  /**
559  * Have GF handle file uploads
560  *
561  * Copy of code from GFFormDisplay::process_form()
562  *
563  * @param int $form_id
564  */
565  private function process_save_process_files( $form_id ) {
566 
567  //Loading files that have been uploaded to temp folder
568  $files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) );
569  if ( ! is_array( $files ) ) {
570  $files = array();
571  }
572 
573  /**
574  * Make sure the fileuploads are not overwritten if no such request was done.
575  * @since 1.20.1
576  */
577  add_filter( "gform_save_field_value_$form_id", array( $this, 'save_field_value' ), 99, 5 );
578 
579  RGFormsModel::$uploaded_files[ $form_id ] = $files;
580  }
581 
582  /**
583  * Make sure the fileuploads are not overwritten if no such request was done.
584  *
585  * TO ONLY BE USED INTERNALLY; DO NOT DEVELOP ON; MAY BE REMOVED AT ANY TIME.
586  *
587  * @since 1.20.1
588  *
589  * @param string $value Field value
590  * @param array $entry GF entry array
591  * @param GF_Field_FileUpload $field
592  * @param array $form GF form array
593  * @param string $input_id ID of the input being saved
594  *
595  * @return string
596  */
597  public function save_field_value( $value = '', $entry = array(), $field = null, $form = array(), $input_id = '' ) {
598 
599  if ( ! $field || $field->type != 'fileupload' ) {
600  return $value;
601  }
602 
603  $input_name = 'input_' . str_replace( '.', '_', $input_id );
604 
605  if ( $field->multipleFiles ) {
606  if ( empty( $value ) ) {
607  return json_decode( \GV\Utils::get( $entry, $input_id, '' ), true );
608  }
609  return $value;
610  }
611 
612  /** No file is being uploaded. */
613  if ( empty( $_FILES[ $input_name ]['name'] ) ) {
614  /** So return the original upload, with $value as backup (it can be empty during edit form rendering) */
615  return rgar( $entry, $input_id, $value );
616  }
617 
618  return $value;
619  }
620 
621  /**
622  * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView
623  * Late validation done on self::custom_validation
624  *
625  * @param $plupload_init array Plupload settings
626  * @param $form_id
627  * @param $instance
628  * @return mixed
629  */
630  public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) {
631  if( ! $this->is_edit_entry() ) {
632  return $plupload_init;
633  }
634 
635  $plupload_init['gf_vars']['max_files'] = 0;
636 
637  return $plupload_init;
638  }
639 
640 
641  /**
642  * Set visibility to visible and convert field input key to string
643  * @return array $form
644  */
645  private function form_prepare_for_save() {
646 
647  $form = $this->filter_conditional_logic( $this->form );
648 
649  /** @type GF_Field $field */
650  foreach( $form['fields'] as $k => &$field ) {
651 
652  /**
653  * Remove the fields with calculation formulas before save to avoid conflicts with GF logic
654  * @since 1.16.3
655  */
656  if( $field->has_calculation() ) {
657  unset( $form['fields'][ $k ] );
658  }
659 
660  $field->adminOnly = false;
661 
662  if( isset( $field->inputs ) && is_array( $field->inputs ) ) {
663  foreach( $field->inputs as $key => $input ) {
664  $field->inputs[ $key ][ 'id' ] = (string)$input['id'];
665  }
666  }
667  }
668 
669  $form['fields'] = array_values( $form['fields'] );
670 
671  return $form;
672  }
673 
674  private function update_calculation_fields() {
675  global $wpdb;
676 
677  $form = self::$original_form;
678  $update = false;
679 
680  // get the most up to date entry values
681  $entry = GFAPI::get_entry( $this->entry['id'] );
682 
683  if ( version_compare( GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=' ) && method_exists( 'GFFormsModel', 'get_entry_meta_table_name' ) ) {
684  $entry_meta_table = GFFormsModel::get_entry_meta_table_name();
685  $current_fields = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $entry_meta_table WHERE entry_id=%d", $entry['id'] ) );
686  } else {
687  $lead_detail_table = GFFormsModel::get_lead_details_table_name();
688  $current_fields = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $lead_detail_table WHERE lead_id=%d", $entry['id'] ) );
689  }
690 
691 
692  if ( ! empty( $this->fields_with_calculation ) ) {
693  $allowed_fields = $this->get_configured_edit_fields( $form, $this->view_id );
694  $allowed_fields = wp_list_pluck( $allowed_fields, 'id' );
695 
696  foreach ( $this->fields_with_calculation as $field ) {
697 
698  if ( in_array( $field->id, $this->unset_hidden_calculations, true ) ) {
699  continue;
700  }
701 
702  $inputs = $field->get_entry_inputs();
703  if ( is_array( $inputs ) ) {
704  foreach ( $inputs as $input ) {
705  list( $field_id, $input_id ) = rgexplode( '.', $input['id'], 2 );
706 
707  if ( 'product' === $field->type ) {
708  $input_name = 'input_' . str_replace( '.', '_', $input['id'] );
709 
710  // Only allow quantity to be set if it's allowed to be edited
711  if ( in_array( $field_id, $allowed_fields ) && $input_id == 3 ) {
712  } else { // otherwise set to what it previously was
713  $_POST[ $input_name ] = $entry[ $input['id'] ];
714  }
715  } else {
716  // Set to what it previously was if it's not editable
717  if ( ! in_array( $field_id, $allowed_fields ) ) {
718  $_POST[ $input_name ] = $entry[ $input['id'] ];
719  }
720  }
721 
722  GFFormsModel::save_input( $form, $field, $entry, $current_fields, $input['id'] );
723  }
724  } else {
725  // Set to what it previously was if it's not editable
726  if ( ! in_array( $field->id, $allowed_fields ) ) {
727  $_POST[ 'input_' . $field->id ] = $entry[ $field->id ];
728  }
729  GFFormsModel::save_input( $form, $field, $entry, $current_fields, $field->id );
730  }
731  }
732 
733  if ( method_exists( 'GFFormsModel', 'commit_batch_field_operations' ) ) {
734  GFFormsModel::commit_batch_field_operations();
735  }
736  }
737  }
738 
739  /**
740  * Handle updating the Post Image field
741  *
742  * Sets a new Featured Image if configured in Gravity Forms; otherwise uploads/updates media
743  *
744  * @since 1.17
745  *
746  * @uses GFFormsModel::media_handle_upload
747  * @uses set_post_thumbnail
748  *
749  * @param array $form GF Form array
750  * @param GF_Field $field GF Field
751  * @param string $field_id Numeric ID of the field
752  * @param string $value
753  * @param array $entry GF Entry currently being edited
754  * @param int $post_id ID of the Post being edited
755  *
756  * @return mixed|string
757  */
759 
760  $input_name = 'input_' . $field_id;
761 
762  if ( !empty( $_FILES[ $input_name ]['name'] ) ) {
763 
764  // We have a new image
765 
766  $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'] );
767 
768  $ary = ! empty( $value ) ? explode( '|:|', $value ) : array();
769  $ary = stripslashes_deep( $ary );
770  $img_url = \GV\Utils::get( $ary, 0 );
771 
772  $img_title = count( $ary ) > 1 ? $ary[1] : '';
773  $img_caption = count( $ary ) > 2 ? $ary[2] : '';
774  $img_description = count( $ary ) > 3 ? $ary[3] : '';
775 
776  $image_meta = array(
777  'post_excerpt' => $img_caption,
778  'post_content' => $img_description,
779  );
780 
781  //adding title only if it is not empty. It will default to the file name if it is not in the array
782  if ( ! empty( $img_title ) ) {
783  $image_meta['post_title'] = $img_title;
784  }
785 
786  /**
787  * 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.
788  * Note: the method became public in GF 1.9.17.7, but we don't require that version yet.
789  */
790  require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php';
792 
793  // is this field set as featured image?
794  if ( $media_id && $field->postFeaturedImage ) {
795  set_post_thumbnail( $post_id, $media_id );
796  }
797 
798  } elseif ( ! empty( $_POST[ $input_name ] ) && is_array( $value ) ) {
799 
800  $img_url = stripslashes_deep( $_POST[ $input_name ] );
801  $img_title = stripslashes_deep( \GV\Utils::_POST( $input_name . '_1' ) );
802  $img_caption = stripslashes_deep( \GV\Utils::_POST( $input_name . '_4' ) );
803  $img_description = stripslashes_deep( \GV\Utils::_POST( $input_name . '_7' ) );
804 
805  $value = ! empty( $img_url ) ? $img_url . "|:|" . $img_title . "|:|" . $img_caption . "|:|" . $img_description : '';
806 
807  if ( $field->postFeaturedImage ) {
808 
809  $image_meta = array(
810  'ID' => get_post_thumbnail_id( $post_id ),
811  'post_title' => $img_title,
812  'post_excerpt' => $img_caption,
813  'post_content' => $img_description,
814  );
815 
816  // update image title, caption or description
817  wp_update_post( $image_meta );
818  }
819  } else {
820 
821  // if we get here, image was removed or not set.
822  $value = '';
823 
824  if ( $field->postFeaturedImage ) {
825  delete_post_thumbnail( $post_id );
826  }
827  }
828 
829  return $value;
830  }
831 
832  /**
833  * Loop through the fields being edited and if they include Post fields, update the Entry's post object
834  *
835  * @param array $form Gravity Forms form
836  *
837  * @return void
838  */
839  private function maybe_update_post_fields( $form ) {
840 
841  if( empty( $this->entry['post_id'] ) ) {
842  gravityview()->log->debug( 'This entry has no post fields. Continuing...' );
843  return;
844  }
845 
846  $post_id = $this->entry['post_id'];
847 
848  // Security check
849  if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) {
850  gravityview()->log->error( 'The current user does not have the ability to edit Post #{post_id}', array( 'post_id' => $post_id ) );
851  return;
852  }
853 
854  $update_entry = false;
855 
856  $updated_post = $original_post = get_post( $post_id );
857 
858  foreach ( $this->entry as $field_id => $value ) {
859 
860  $field = RGFormsModel::get_field( $form, $field_id );
861 
862  if( ! $field ) {
863  continue;
864  }
865 
866  if( GFCommon::is_post_field( $field ) && 'post_category' !== $field->type ) {
867 
868  // Get the value of the field, including $_POSTed value
869  $value = RGFormsModel::get_field_value( $field );
870 
871  // Use temporary entry variable, to make values available to fill_post_template() and update_post_image()
872  $entry_tmp = $this->entry;
873  $entry_tmp["{$field_id}"] = $value;
874 
875  switch( $field->type ) {
876 
877  case 'post_title':
878  $post_title = $value;
879  if ( \GV\Utils::get( $form, 'postTitleTemplateEnabled' ) ) {
880  $post_title = $this->fill_post_template( $form['postTitleTemplate'], $form, $entry_tmp );
881  }
882  $updated_post->post_title = $post_title;
883  $updated_post->post_name = $post_title;
884  unset( $post_title );
885  break;
886 
887  case 'post_content':
888  $post_content = $value;
889  if ( \GV\Utils::get( $form, 'postContentTemplateEnabled' ) ) {
890  $post_content = $this->fill_post_template( $form['postContentTemplate'], $form, $entry_tmp, true );
891  }
892  $updated_post->post_content = $post_content;
893  unset( $post_content );
894  break;
895  case 'post_excerpt':
896  $updated_post->post_excerpt = $value;
897  break;
898  case 'post_tags':
899  wp_set_post_tags( $post_id, $value, false );
900  break;
901  case 'post_category':
902  break;
903  case 'post_custom_field':
904  if ( is_array( $value ) && ( floatval( $field_id ) !== floatval( $field->id ) ) ) {
905  $value = $value[ $field_id ];
906  }
907 
908  if( ! empty( $field->customFieldTemplateEnabled ) ) {
909  $value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true );
910  }
911 
912  $value = $field->get_value_save_entry( $value, $form, '', $this->entry['id'], $this->entry );
913 
914  update_post_meta( $post_id, $field->postCustomFieldName, $value );
915  break;
916 
917  case 'post_image':
918  $value = $this->update_post_image( $form, $field, $field_id, $value, $this->entry, $post_id );
919  break;
920 
921  }
922 
923  // update entry after
924  $this->entry["{$field_id}"] = $value;
925 
926  $update_entry = true;
927 
928  unset( $entry_tmp );
929  }
930 
931  }
932 
933  if( $update_entry ) {
934 
935  $return_entry = GFAPI::update_entry( $this->entry );
936 
937  if( is_wp_error( $return_entry ) ) {
938  gravityview()->log->error( 'Updating the entry post fields failed', array( 'data' => array( '$this->entry' => $this->entry, '$return_entry' => $return_entry ) ) );
939  } else {
940  gravityview()->log->debug( 'Updating the entry post fields for post #{post_id} succeeded', array( 'post_id' => $post_id ) );
941  }
942 
943  }
944 
945  $return_post = wp_update_post( $updated_post, true );
946 
947  if( is_wp_error( $return_post ) ) {
948  $return_post->add_data( $updated_post, '$updated_post' );
949  gravityview()->log->error( 'Updating the post content failed', array( 'data' => compact( 'updated_post', 'return_post' ) ) );
950  } else {
951  gravityview()->log->debug( 'Updating the post content for post #{post_id} succeeded', array( 'post_id' => $post_id, 'data' => $updated_post ) );
952  }
953  }
954 
955  /**
956  * Convert a field content template into prepared output
957  *
958  * @uses GravityView_GFFormsModel::get_post_field_images()
959  *
960  * @since 1.17
961  *
962  * @param string $template The content template for the field
963  * @param array $form Gravity Forms form
964  * @param bool $do_shortcode Whether to process shortcode inside content. In GF, only run on Custom Field and Post Content fields
965  *
966  * @return string
967  */
968  private function fill_post_template( $template, $form, $entry, $do_shortcode = false ) {
969 
970  require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php';
971 
973 
974  //replacing post image variables
975  $output = GFCommon::replace_variables_post_image( $template, $post_images, $entry );
976 
977  //replacing all other variables
978  $output = GFCommon::replace_variables( $output, $form, $entry, false, false, false );
979 
980  // replace conditional shortcodes
981  if( $do_shortcode ) {
982  $output = do_shortcode( $output );
983  }
984 
985  return $output;
986  }
987 
988 
989  /**
990  * Perform actions normally performed after updating a lead
991  *
992  * @since 1.8
993  *
994  * @see GFEntryDetail::lead_detail_page()
995  *
996  * @return void
997  */
998  private function after_update() {
999 
1000  do_action( 'gform_after_update_entry', self::$original_form, $this->entry['id'], self::$original_entry );
1001  do_action( "gform_after_update_entry_{$this->form['id']}", self::$original_form, $this->entry['id'], self::$original_entry );
1002 
1003  // Re-define the entry now that we've updated it.
1004  $entry = RGFormsModel::get_lead( $this->entry['id'] );
1005 
1006  $entry = GFFormsModel::set_entry_meta( $entry, self::$original_form );
1007 
1008  if ( version_compare( GFFormsModel::get_database_version(), '2.3-dev-1', '<' ) ) {
1009  // We need to clear the cache because Gravity Forms caches the field values, which
1010  // we have just updated.
1011  foreach ($this->form['fields'] as $key => $field) {
1012  GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id );
1013  }
1014  }
1015 
1016  /**
1017  * Maybe process feeds.
1018  *
1019  * @since develop
1020  */
1021  if ( $allowed_feeds = $this->view->settings->get( 'edit_feeds', array() ) ) {
1022  $feeds = GFAPI::get_feeds( null, $entry['form_id'] );
1023  if ( ! is_wp_error( $feeds ) ) {
1024  $registered_feeds = array();
1025  foreach ( GFAddOn::get_registered_addons() as $registered_feed ) {
1026  if ( is_subclass_of( $registered_feed, 'GFFeedAddOn' ) ) {
1027  if ( method_exists( $registered_feed, 'get_instance' ) ) {
1028  $registered_feed = call_user_func( array( $registered_feed, 'get_instance' ) );
1029  $registered_feeds[ $registered_feed->get_slug() ] = $registered_feed;
1030  }
1031  }
1032  }
1033  foreach ( $feeds as $feed ) {
1034  if ( in_array( $feed['id'], $allowed_feeds ) ) {
1035  if ( $feed_object = \GV\Utils::get( $registered_feeds, $feed['addon_slug'] ) ) {
1036  $returned_entry = $feed_object->process_feed( $feed, $entry, self::$original_form );
1037  if ( is_array( $returned_entry ) && rgar( $returned_entry, 'id' ) ) {
1038  $entry = $returned_entry;
1039  }
1040 
1041  do_action( 'gform_post_process_feed', $feed, $entry, self::$original_form, $feed_object );
1042  $slug = $feed_object->get_slug();
1043  do_action( "gform_{$slug}_post_process_feed", $feed, $entry, self::$original_form, $feed_object );
1044  }
1045  }
1046  }
1047  }
1048  }
1049 
1050  $this->entry = $entry;
1051  }
1052 
1053 
1054  /**
1055  * Display the Edit Entry form
1056  *
1057  * @return void
1058  */
1059  public function edit_entry_form() {
1060 
1061  $view = \GV\View::by_id( $this->view_id );
1062 
1063  if( $view->settings->get( 'edit_locking' ) ) {
1064  $locking = new GravityView_Edit_Entry_Locking();
1065  $locking->maybe_lock_object( $this->entry['id'] );
1066  }
1067 
1068  ?>
1069 
1070  <div id="wpfooter"></div><!-- used for locking message -->
1071 
1072  <script>
1073  var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>';
1074  </script>
1075 
1076  <div class="gv-edit-entry-wrapper"><?php
1077 
1078  $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this );
1079 
1080  /**
1081  * Fixes weird wpautop() issue
1082  * @see https://github.com/katzwebservices/GravityView/issues/451
1083  */
1084  echo gravityview_strip_whitespace( $javascript );
1085 
1086  ?><h2 class="gv-edit-entry-title">
1087  <span><?php
1088 
1089  /**
1090  * @filter `gravityview_edit_entry_title` Modify the edit entry title
1091  * @param string $edit_entry_title Modify the "Edit Entry" title
1092  * @param GravityView_Edit_Entry_Render $this This object
1093  */
1094  $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gk-gravityview'), $this );
1095 
1096  echo esc_attr( $edit_entry_title );
1097  ?></span>
1098  </h2>
1099 
1100  <?php $this->maybe_print_message(); ?>
1101 
1102  <?php // The ID of the form needs to be `gform_{form_id}` for the pluploader ?>
1103 
1104  <form method="post" id="gform_<?php echo $this->form_id; ?>" enctype="multipart/form-data">
1105 
1106  <?php
1107 
1108  wp_nonce_field( self::$nonce_key, self::$nonce_key );
1109 
1110  wp_nonce_field( self::$nonce_field, self::$nonce_field, false );
1111 
1112  // Print the actual form HTML
1113  $this->render_edit_form();
1114 
1115  ?>
1116  </form>
1117 
1118  <script>
1119  gform.addFilter('gform_reset_pre_conditional_logic_field_action', function ( reset, formId, targetId, defaultValues, isInit ) {
1120  return false;
1121  });
1122  </script>
1123 
1124  </div>
1125 
1126  <?php
1127  }
1128 
1129  /**
1130  * Display success or error message if the form has been submitted
1131  *
1132  * @uses GVCommon::generate_notice
1133  *
1134  * @since 1.16.2.2
1135  *
1136  * @return void
1137  */
1138  private function maybe_print_message() {
1139 
1140  if ( \GV\Utils::_POST( 'action' ) !== 'update' ) {
1141  return;
1142  }
1143 
1144  /**
1145  * @filter `gravityview/features/paged-edit`
1146  * @since 2.5
1147  * @since 2.14 Added the $form argument
1148  * @param bool $enable_paged_edit Should paged editing be supported?
1149  * @param array $form The current form connected to the entry being edited
1150  */
1151  $enable_paged_edit = apply_filters( 'gravityview/features/paged-edit', false, $this->form );
1152 
1153  if ( GFCommon::has_pages( $this->form ) && $enable_paged_edit ) {
1154  $labels = array(
1155  'cancel' => __( 'Cancel', 'gk-gravityview' ),
1156  'submit' => __( 'Update', 'gk-gravityview' ),
1157  'next' => __( 'Next', 'gk-gravityview' ),
1158  'previous' => __( 'Previous', 'gk-gravityview' ),
1159  );
1160 
1161  /**
1162  * @filter `gravityview/edit_entry/button_labels` Modify the cancel/submit buttons' labels
1163  * @since 1.16.3
1164  * @param array $labels Default button labels associative array
1165  * @param array $form The Gravity Forms form
1166  * @param array $entry The Gravity Forms entry
1167  * @param int $view_id The current View ID
1168  */
1169  $labels = apply_filters( 'gravityview/edit_entry/button_labels', $labels, $this->form, $this->entry, $this->view_id );
1170 
1171  $this->is_paged_submitted = \GV\Utils::_POST( 'save' ) === $labels['submit'];
1172  }
1173 
1174  $back_link = remove_query_arg( array( 'page', 'view', 'edit', 'gvid' ) );
1175 
1176  if( ! $this->is_valid ){
1177 
1178  // Keeping this compatible with Gravity Forms.
1179  $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gk-gravityview') . " " . __('Errors have been highlighted below.', 'gk-gravityview') . "</div>";
1180  $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form);
1181 
1182  echo GVCommon::generate_notice( $message , 'gv-error' );
1183 
1184  } elseif ( false === $this->is_paged_submitted ) {
1185  // Paged form that hasn't been submitted on the last page yet
1186  $entry_updated_message = sprintf( esc_attr__( 'Entry Updated.', 'gk-gravityview' ), '<a href="' . esc_url( $back_link ) . '">', '</a>' );
1187 
1188  /**
1189  * @filter `gravityview/edit_entry/page/success` Modify the edit entry success message on pages
1190  * @since develop
1191  * @param string $entry_updated_message Existing message
1192  * @param int $view_id View ID
1193  * @param array $entry Gravity Forms entry array
1194  */
1195  $message = apply_filters( 'gravityview/edit_entry/page/success', $entry_updated_message , $this->view_id, $this->entry );
1196 
1197  echo GVCommon::generate_notice( $message );
1198  } else {
1199  $view = \GV\View::by_id( $this->view_id );
1200  $edit_redirect = $view->settings->get( 'edit_redirect' );
1201  $edit_redirect_url = $view->settings->get( 'edit_redirect_url' );
1202 
1203  switch ( $edit_redirect ) {
1204 
1205  case '0':
1206  $redirect_url = $back_link;
1207  $entry_updated_message = sprintf( esc_attr_x('Entry Updated. %sReturning to Entry%s', 'Replacements are HTML', 'gk-gravityview'), '<a href="'. esc_url( $redirect_url ) .'">', '</a>' );
1208  break;
1209 
1210  case '1':
1211  $redirect_url = $directory_link = GravityView_API::directory_link();
1212  $entry_updated_message = sprintf( esc_attr_x('Entry Updated. %sReturning to %s%s', 'Replacement 1 is HTML. Replacement 2 is the title of the page where the user will be taken. Replacement 3 is HTML.','gk-gravityview'), '<a href="'. esc_url( $redirect_url ) . '">', esc_html( $view->post_title ), '</a>' );
1213  break;
1214 
1215  case '2':
1216  $redirect_url = $edit_redirect_url;
1217  $redirect_url = GFCommon::replace_variables( $redirect_url, $this->form, $this->entry, false, false, false, 'text' );
1218  $entry_updated_message = sprintf( esc_attr_x('Entry Updated. %sRedirecting to %s%s', 'Replacement 1 is HTML. Replacement 2 is the URL where the user will be taken. Replacement 3 is HTML.','gk-gravityview'), '<a href="'. esc_url( $redirect_url ) . '">', esc_html( $edit_redirect_url ), '</a>' );
1219  break;
1220 
1221  case '':
1222  default:
1223  $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gk-gravityview'), '<a href="'. esc_url( $back_link ) .'">', '</a>' );
1224  break;
1225  }
1226 
1227  if ( isset( $redirect_url ) ) {
1228  $entry_updated_message .= sprintf( '<script>window.location.href = %s;</script><noscript><meta http-equiv="refresh" content="0;URL=%s" /></noscript>', json_encode( $redirect_url ), esc_attr( $redirect_url ) );
1229  }
1230 
1231  /**
1232  * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link)
1233  *
1234  * @since 1.5.4
1235  *
1236  * @param string $entry_updated_message Existing message
1237  * @param int $view_id View ID
1238  * @param array $entry Gravity Forms entry array
1239  * @param string $back_link URL to return to the original entry. @since 1.6
1240  * @param string|null $redirect_url URL to return to after the update. @since 2.14.6
1241  */
1242  $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message, $this->view_id, $this->entry, $back_link, isset( $redirect_url ) ? $redirect_url : null );
1243 
1244  echo GVCommon::generate_notice( $message );
1245  }
1246  }
1247 
1248  /**
1249  * Display the Edit Entry form in the original Gravity Forms format
1250  *
1251  * @since 1.9
1252  *
1253  * @return void
1254  */
1255  private function render_edit_form() {
1256 
1257  /**
1258  * @action `gravityview/edit-entry/render/before` Before rendering the Edit Entry form
1259  * @since 1.17
1260  * @param GravityView_Edit_Entry_Render $this
1261  */
1262  do_action( 'gravityview/edit-entry/render/before', $this );
1263 
1264  add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 );
1265  add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') );
1266  add_filter( 'gform_next_button', array( $this, 'render_form_buttons' ) );
1267  add_filter( 'gform_previous_button', array( $this, 'render_form_buttons' ) );
1268  add_filter( 'gform_disable_view_counter', '__return_true' );
1269 
1270  add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 );
1271  add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 );
1272 
1273  // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin.
1274  unset( $_GET['page'] );
1275 
1276  $this->show_next_button = false;
1277  $this->show_previous_button = false;
1278 
1279  // TODO: Verify multiple-page forms
1280  if ( GFCommon::has_pages( $this->form ) && apply_filters( 'gravityview/features/paged-edit', false ) ) {
1281  if ( intval( $page_number = \GV\Utils::_POST( 'gform_source_page_number_' . $this->form['id'], 0 ) ) ) {
1282 
1283  $labels = array(
1284  'cancel' => __( 'Cancel', 'gk-gravityview' ),
1285  'submit' => __( 'Update', 'gk-gravityview' ),
1286  'next' => __( 'Next', 'gk-gravityview' ),
1287  'previous' => __( 'Previous', 'gk-gravityview' ),
1288  );
1289 
1290  /**
1291  * @filter `gravityview/edit_entry/button_labels` Modify the cancel/submit buttons' labels
1292  * @since 1.16.3
1293  * @param array $labels Default button labels associative array
1294  * @param array $form The Gravity Forms form
1295  * @param array $entry The Gravity Forms entry
1296  * @param int $view_id The current View ID
1297  */
1298  $labels = apply_filters( 'gravityview/edit_entry/button_labels', $labels, $this->form, $this->entry, $this->view_id );
1299 
1300  GFFormDisplay::$submission[ $this->form['id'] ][ 'form' ] = $this->form;
1301  GFFormDisplay::$submission[ $this->form['id'] ][ 'is_valid' ] = true;
1302 
1303  if ( \GV\Utils::_POST( 'save' ) === $labels['next'] ) {
1304  $last_page = \GFFormDisplay::get_max_page_number( $this->form );
1305 
1306  while ( ++$page_number < $last_page && RGFormsModel::is_page_hidden( $this->form, $page_number, \GV\Utils::_POST( 'gform_field_values' ) ) ) {
1307  } // Advance to next visible page
1308  } elseif ( \GV\Utils::_POST( 'save' ) === $labels['previous'] ) {
1309  while ( --$page_number > 1 && RGFormsModel::is_page_hidden( $this->form, $page_number, \GV\Utils::_POST( 'gform_field_values' ) ) ) {
1310  } // Advance to next visible page
1311  }
1312 
1313  GFFormDisplay::$submission[ $this->form['id'] ]['page_number'] = $page_number;
1314  }
1315 
1316  if ( ( $page_number = intval( $page_number ) ) < 2 ) {
1317  $this->show_next_button = true; // First page
1318  }
1319 
1320  $last_page = \GFFormDisplay::get_max_page_number( $this->form );
1321 
1322  $has_more_pages = $page_number < $last_page;
1323 
1324  if ( $has_more_pages ) {
1325  $this->show_next_button = true; // Not the last page
1326  } else {
1327  $this->show_update_button = true; // The last page
1328  }
1329 
1330  if ( $page_number > 1 ) {
1331  $this->show_previous_button = true; // Not the first page
1332  }
1333  } else {
1334  $this->show_update_button = true;
1335  }
1336 
1337  ob_start(); // Prevent PHP warnings possibly caused by prefilling list fields for conditional logic
1338 
1339  $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry );
1340 
1341  ob_get_clean();
1342 
1343  remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 );
1344  remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) );
1345  remove_filter( 'gform_next_button', array( $this, 'render_form_buttons' ) );
1346  remove_filter( 'gform_previous_button', array( $this, 'render_form_buttons' ) );
1347  remove_filter( 'gform_disable_view_counter', '__return_true' );
1348  remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 );
1349  remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 );
1350 
1351  echo $html;
1352 
1353  /**
1354  * @action `gravityview/edit-entry/render/after` After rendering the Edit Entry form
1355  * @since 1.17
1356  * @param GravityView_Edit_Entry_Render $this
1357  */
1358  do_action( 'gravityview/edit-entry/render/after', $this );
1359  }
1360 
1361  /**
1362  * Display the Update/Cancel/Delete buttons for the Edit Entry form
1363  * @since 1.8
1364  * @return string
1365  */
1366  public function render_form_buttons() {
1367  return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this );
1368  }
1369 
1370 
1371  /**
1372  * Modify the form fields that are shown when using GFFormDisplay::get_form()
1373  *
1374  * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown.
1375  *
1376  * @param array $form
1377  * @param boolean $ajax Whether in AJAX mode
1378  * @param array|string $field_values Passed parameters to the form
1379  *
1380  * @since 1.9
1381  *
1382  * @return array Modified form array
1383  */
1384  public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) {
1385 
1386  if( $form['id'] != $this->form_id ) {
1387  return $form;
1388  }
1389 
1390  // In case we have validated the form, use it to inject the validation results into the form render
1391  if( isset( $this->form_after_validation ) && $this->form_after_validation['id'] === $form['id'] ) {
1393  } else {
1394  $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id );
1395  }
1396 
1397  $form = $this->filter_conditional_logic( $form );
1398 
1399  $form = $this->prefill_conditional_logic( $form );
1400 
1401  // for now we don't support Save and Continue feature.
1402  if( ! self::$supports_save_and_continue ) {
1403  unset( $form['save'] );
1404  }
1405 
1406  $form = $this->unselect_default_values( $form );
1407 
1408  return $form;
1409  }
1410 
1411  /**
1412  * 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.
1413  *
1414  * @since 1.16.2.2
1415  *
1416  * @param string $field_content Always empty. Returning not-empty overrides the input.
1417  * @param GF_Field $field
1418  * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
1419  * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
1420  * @param int $form_id Form ID
1421  *
1422  * @return string If error, the error message. If no error, blank string (modify_edit_field_input() runs next)
1423  */
1424  public function verify_user_can_edit_post( $field_content = '', $field = null, $value = '', $lead_id = 0, $form_id = 0 ) {
1425 
1426  if( ! GFCommon::is_post_field( $field ) ) {
1427  return $field_content;
1428  }
1429 
1430  $message = null;
1431 
1432  // First, make sure they have the capability to edit the post.
1433  if( null === get_post( $this->entry['post_id'] ) ) {
1434  /**
1435  * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists
1436  * @param string $message The existing "This field is not editable; the post no longer exists." text
1437  */
1438  $message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gk-gravityview' ) );
1439  } elseif( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) {
1440  /**
1441  * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post
1442  * @param string $message The existing "You don't have permission..." text
1443  */
1444  $message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don&rsquo;t have permission to edit this post.', 'gk-gravityview') );
1445  }
1446 
1447  if( $message ) {
1448  $field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) );
1449  }
1450 
1451  return $field_content;
1452  }
1453 
1454  /**
1455  *
1456  * Fill-in the saved values into the form inputs
1457  *
1458  * @param string $field_content Always empty. Returning not-empty overrides the input.
1459  * @param GF_Field $field
1460  * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
1461  * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
1462  * @param int $form_id Form ID
1463  *
1464  * @return mixed
1465  */
1466  public function modify_edit_field_input( $field_content = '', $field = null, $value = '', $lead_id = 0, $form_id = 0 ) {
1467 
1469 
1470  // If the form has been submitted, then we don't need to pre-fill the values,
1471  // Except for fileupload type and when a field input is overridden- run always!!
1472  if(
1473  ( $this->is_edit_entry_submission() && !in_array( $field->type, array( 'fileupload', 'post_image' ) ) )
1474  && false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) )
1475  && ! GFCommon::is_product_field( $field->type )
1476  || ! empty( $field_content )
1477  || in_array( $field->type, array( 'honeypot' ) )
1478  ) {
1479  return $field_content;
1480  }
1481 
1482  // SET SOME FIELD DEFAULTS TO PREVENT ISSUES
1483  $field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */
1484 
1485  $field_value = $this->get_field_value( $field );
1486 
1487  // Prevent any PHP warnings, like undefined index
1488  ob_start();
1489 
1490  $return = null;
1491 
1492  /** @var GravityView_Field $gv_field */
1493  if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) {
1494  $return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field );
1495  } else {
1496  $return = $field->get_field_input( $this->form, $field_value, $this->entry );
1497  }
1498 
1499  // If there was output, it's an error
1500  $warnings = ob_get_clean();
1501 
1502  if( !empty( $warnings ) ) {
1503  gravityview()->log->error( '{warning}', array( 'warning' => $warnings, 'data' => $field_value ) );
1504  }
1505 
1506  return $return;
1507  }
1508 
1509  /**
1510  * Modify the value for the current field input
1511  *
1512  * @param GF_Field $field
1513  *
1514  * @return array|mixed|string
1515  */
1516  private function get_field_value( $field ) {
1517 
1518  /**
1519  * @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.
1520  * @param boolean True: override saved values; False: don't override (default)
1521  * @param $field GF_Field object Gravity Forms field object
1522  * @since 1.13
1523  */
1524  $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field );
1525 
1526  // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs)
1527  if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) {
1528 
1529  $field_value = array();
1530 
1531  // only accept pre-populated values if the field doesn't have any choice selected.
1532  $allow_pre_populated = $field->allowsPrepopulate;
1533 
1534  foreach ( (array)$field->inputs as $input ) {
1535 
1536  $input_id = strval( $input['id'] );
1537 
1538  if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) {
1539  $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ];
1540  $allow_pre_populated = false;
1541  }
1542 
1543  }
1544 
1545  $pre_value = $field->get_value_submission( array(), false );
1546 
1547  $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value;
1548 
1549  } else {
1550 
1551  $id = intval( $field->id );
1552 
1553  // get pre-populated value if exists
1554  $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : '';
1555 
1556  // saved field entry value (if empty, fallback to the pre-populated value, if exists)
1557  // or pre-populated value if not empty and set to override saved value
1558  $field_value = isset( $this->entry[ $id ] ) && ! gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value;
1559 
1560  // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs.
1561  if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) {
1562  $categories = array();
1563  foreach ( explode( ',', $field_value ) as $cat_string ) {
1564  $categories[] = GFCommon::format_post_category( $cat_string, true );
1565  }
1566  $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories );
1567  }
1568 
1569  }
1570 
1571  // if value is empty get the default value if defined
1572  $field_value = $field->get_value_default_if_empty( $field_value );
1573 
1574  /**
1575  * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed
1576  * @since 1.11
1577  * @since 1.20 Added third param
1578  * @param mixed $field_value field value used to populate the input
1579  * @param object $field Gravity Forms field object ( Class GF_Field )
1580  * @param GravityView_Edit_Entry_Render $this Current object
1581  */
1582  $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field, $this );
1583 
1584  /**
1585  * @filter `gravityview/edit_entry/field_value_{field_type}` Change the value of an Edit Entry field for a specific field type
1586  * @since 1.17
1587  * @since 1.20 Added third param
1588  * @param mixed $field_value field value used to populate the input
1589  * @param GF_Field $field Gravity Forms field object
1590  * @param GravityView_Edit_Entry_Render $this Current object
1591  */
1592  $field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type , $field_value, $field, $this );
1593 
1594  return $field_value;
1595  }
1596 
1597 
1598  // ---- Entry validation
1599 
1600  /**
1601  * Add field keys that Gravity Forms expects.
1602  *
1603  * @see GFFormDisplay::validate()
1604  * @param array $form GF Form
1605  * @return array Modified GF Form
1606  */
1607  public function gform_pre_validation( $form ) {
1608 
1609  if( ! $this->verify_nonce() ) {
1610  return $form;
1611  }
1612 
1613  // Fix PHP warning regarding undefined index.
1614  foreach ( $form['fields'] as &$field) {
1615 
1616  // This is because we're doing admin form pretending to be front-end, so Gravity Forms
1617  // expects certain field array items to be set.
1618  foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) {
1619  $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL;
1620  }
1621 
1622  switch( RGFormsModel::get_input_type( $field ) ) {
1623 
1624  /**
1625  * 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.
1626  *
1627  * 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.
1628  *
1629  * @hack
1630  */
1631  case 'fileupload':
1632 
1633  // Set the previous value
1634  $entry = $this->get_entry();
1635 
1636  $input_name = 'input_'.$field->id;
1637  $form_id = $form['id'];
1638 
1639  $value = NULL;
1640 
1641  // Use the previous entry value as the default.
1642  if( isset( $entry[ $field->id ] ) ) {
1643  $value = $entry[ $field->id ];
1644  }
1645 
1646  // If this is a single upload file
1647  if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) {
1648  $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] );
1649  $value = $file_path['url'];
1650 
1651  } else {
1652 
1653  // Fix PHP warning on line 1498 of form_display.php for post_image fields
1654  // Fix PHP Notice: Undefined index: size in form_display.php on line 1511
1655  $_FILES[ $input_name ] = array('name' => '', 'size' => '' );
1656 
1657  }
1658 
1659  if ( \GV\Utils::get( $field, 'multipleFiles' ) ) {
1660  // If there are fresh uploads, process and merge them.
1661  // Otherwise, use the passed values, which should be json-encoded array of URLs
1662  if ( isset( GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] ) ) {
1663  $value = empty( $value ) ? '[]' : $value;
1664  $value = stripslashes_deep( $value );
1665  $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array() );
1666  } else if ( GFCommon::is_json( $value ) ) {
1667  // Existing file; let GF derive the value from the `$_gf_uploaded_files` object (see `\GF_Field_FileUpload::get_multifile_value()`)
1668  global $_gf_uploaded_files;
1669 
1670  $_gf_uploaded_files[ $input_name ] = $value;
1671  }
1672  } else {
1673  // A file already exists when editing an entry
1674  // We set this to solve issue when file upload fields are required.
1675  GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value;
1676  }
1677 
1678  $this->entry[ $input_name ] = $value;
1679  $_POST[ $input_name ] = $value;
1680 
1681  break;
1682 
1683  case 'number':
1684  // Fix "undefined index" issue at line 1286 in form_display.php
1685  if( !isset( $_POST['input_'.$field->id ] ) ) {
1686  $_POST['input_'.$field->id ] = NULL;
1687  }
1688  break;
1689  }
1690 
1691  }
1692 
1693  return $form;
1694  }
1695 
1696 
1697  /**
1698  * Process validation for a edit entry submission
1699  *
1700  * Sets the `is_valid` object var
1701  *
1702  * @return void
1703  */
1704  private function validate() {
1705 
1706  /**
1707  * If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry
1708  * GF User Registration Add-on version > 3.x has a different class name
1709  * @since 1.16.2
1710  */
1711  if ( class_exists( 'GF_User_Registration' ) ) {
1712  remove_filter( 'gform_validation', array( GF_User_Registration::get_instance(), 'validate' ) );
1713  } else if ( class_exists( 'GFUser' ) ) {
1714  remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) );
1715  }
1716 
1717 
1718  /**
1719  * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions.
1720  * You can enter whatever you want!
1721  * We try validating, and customize the results using `self::custom_validation()`
1722  */
1723  add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4);
1724 
1725  // Needed by the validate funtion
1726  $failed_validation_page = NULL;
1727  $field_values = RGForms::post( 'gform_field_values' );
1728 
1729  // Prevent entry limit from running when editing an entry, also
1730  // prevent form scheduling from preventing editing
1731  unset( $this->form['limitEntries'], $this->form['scheduleForm'] );
1732 
1733  // Hide fields depending on Edit Entry settings
1734  $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id );
1735 
1736  $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page );
1737 
1738  remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 );
1739  }
1740 
1741 
1742  /**
1743  * Make validation work for Edit Entry
1744  *
1745  * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end
1746  * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post
1747  * fields. This goes through all the fields and if they're an invalid post field, we
1748  * set them as valid. If there are still issues, we'll return false.
1749  *
1750  * @param $validation_results {
1751  * @type bool $is_valid
1752  * @type array $form
1753  * @type int $failed_validation_page The page number which has failed validation.
1754  * }
1755  *
1756  * @return array
1757  */
1758  public function custom_validation( $validation_results ) {
1759 
1760  gravityview()->log->debug( 'GravityView_Edit_Entry[custom_validation] Validation results: ', array( 'data' => $validation_results ) );
1761 
1762  gravityview()->log->debug( 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', array( 'data' => esc_html( print_r( $_POST, true ) ) ) );
1763 
1764  $gv_valid = true;
1765 
1766  foreach ( $validation_results['form']['fields'] as $key => &$field ) {
1767  $value = RGFormsModel::get_field_value( $field );
1768  $field_type = RGFormsModel::get_input_type( $field );
1769  $is_required = ! empty( $field->isRequired );
1770  $failed_validation = ! empty( $field->failed_validation );
1771 
1772  // Manually validate required fields as they can be skipped be skipped by GF's validation
1773  // This can happen when the field is considered "hidden" (see `GFFormDisplay::validate`) due to unmet conditional logic
1774  if ( $is_required && !$failed_validation && rgblank( $value ) ) {
1775  $field->failed_validation = true;
1776  $field->validation_message = esc_html__( 'This field is required.', 'gk-gravityview' );
1777 
1778  continue;
1779  }
1780 
1781  switch ( $field_type ) {
1782  case 'fileupload':
1783  case 'post_image':
1784  // Clear "this field is required" validation result when no files were uploaded but already exist on the server
1785  if ( $is_required && $failed_validation && ! empty( $value ) ) {
1786  $field->failed_validation = false;
1787 
1788  unset( $field->validation_message );
1789  }
1790 
1791  // Re-validate the field
1792  $field->validate( $field, $this->form );
1793 
1794  // Validate if multi-file upload reached max number of files [maxFiles] => 2
1795  if ( \GV\Utils::get( $field, 'maxFiles' ) && \GV\Utils::get( $field, 'multipleFiles' ) ) {
1796  $input_name = 'input_' . $field->id;
1797  //uploaded
1798  $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array();
1799 
1800  //existent
1801  $entry = $this->get_entry();
1802  $value = null;
1803  if ( isset( $entry[ $field->id ] ) ) {
1804  $value = json_decode( $entry[ $field->id ], true );
1805  }
1806 
1807  // count uploaded files and existent entry files
1808  $count_files = ( is_array( $file_names ) ? count( $file_names ) : 0 ) +
1809  ( is_array( $value ) ? count( $value ) : 0 );
1810 
1811  if ( $count_files > $field->maxFiles ) {
1812  $field->validation_message = __( 'Maximum number of files reached', 'gk-gravityview' );
1813  $field->failed_validation = true;
1814  $gv_valid = false;
1815 
1816  // in case of error make sure the newest upload files are removed from the upload input
1817  GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null;
1818  }
1819  }
1820 
1821  break;
1822  }
1823 
1824  // This field has failed validation.
1825  if( !empty( $field->failed_validation ) ) {
1826 
1827  gravityview()->log->debug( 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'data' => array( 'field' => $field, 'value' => $value ) ) );
1828 
1829  switch ( $field_type ) {
1830 
1831  // Captchas don't need to be re-entered.
1832  case 'captcha':
1833 
1834  // Post Image fields aren't editable, so we un-fail them.
1835  case 'post_image':
1836  $field->failed_validation = false;
1837  unset( $field->validation_message );
1838  break;
1839 
1840  }
1841 
1842  // You can't continue inside a switch, so we do it after.
1843  if( empty( $field->failed_validation ) ) {
1844  continue;
1845  }
1846 
1847  // checks if the No Duplicates option is not validating entry against itself, since
1848  // we're editing a stored entry, it would also assume it's a duplicate.
1849  if( !empty( $field->noDuplicates ) ) {
1850 
1851  $entry = $this->get_entry();
1852 
1853  // If the value of the entry is the same as the stored value
1854  // Then we can assume it's not a duplicate, it's the same.
1855  if( !empty( $entry ) && $value == $entry[ $field->id ] ) {
1856  //if value submitted was not changed, then don't validate
1857  $field->failed_validation = false;
1858 
1859  unset( $field->validation_message );
1860 
1861  gravityview()->log->debug( 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', array( 'data' => $entry ) );
1862 
1863  continue;
1864  }
1865  }
1866 
1867  // if here then probably we are facing the validation 'At least one field must be filled out'
1868  if( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) {
1869  unset( $field->validation_message );
1870  $field->failed_validation = false;
1871  continue;
1872  }
1873 
1874  $gv_valid = false;
1875 
1876  }
1877 
1878  }
1879 
1880  $validation_results['is_valid'] = $gv_valid;
1881 
1882  gravityview()->log->debug( 'GravityView_Edit_Entry[custom_validation] Validation results.', array( 'data' => $validation_results ) );
1883 
1884  // We'll need this result when rendering the form ( on GFFormDisplay::get_form )
1885  $this->form_after_validation = $validation_results['form'];
1886 
1887  return $validation_results;
1888  }
1889 
1890 
1891  /**
1892  * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()!
1893  * Get the current entry and set it if it's not yet set.
1894  * @return array Gravity Forms entry array
1895  */
1896  public function get_entry() {
1897 
1898  if( empty( $this->entry ) ) {
1899  // Get the database value of the entry that's being edited
1901  }
1902 
1903  return $this->entry;
1904  }
1905 
1906 
1907 
1908  // --- Filters
1909 
1910  /**
1911  * Get the Edit Entry fields as configured in the View
1912  *
1913  * @since 1.8
1914  *
1915  * @param int $view_id
1916  *
1917  * @return array Array of fields that are configured in the Edit tab in the Admin
1918  */
1920 
1921  // Get all fields for form
1922  if ( \GV\View::exists( $view_id ) ) {
1924  $properties = $view->fields ? $view->fields->as_configuration() : array();
1925  } else {
1926  $properties = null;
1927  }
1928 
1929  // If edit tab not yet configured, show all fields
1930  $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL;
1931 
1932  // Hide fields depending on admin settings
1933  $fields = $this->filter_fields( $form['fields'], $edit_fields );
1934 
1935  // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't.
1936  $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id );
1937 
1938  /**
1939  * @filter `gravityview/edit_entry/form_fields` Modify the fields displayed in Edit Entry form
1940  * @since 1.17
1941  * @param GF_Field[] $fields Gravity Forms form fields
1942  * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration
1943  * @param array $form GF Form array (`fields` key modified to have only fields configured to show in Edit Entry)
1944  * @param int $view_id View ID
1945  */
1946  $fields = apply_filters( 'gravityview/edit_entry/form_fields', $fields, $edit_fields, $form, $view_id );
1947 
1948  return $fields;
1949  }
1950 
1951 
1952  /**
1953  * Filter area fields based on specified conditions
1954  * - This filter removes the fields that have calculation configured
1955  * - Hides fields that are hidden, etc.
1956  *
1957  * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps
1958  * @access private
1959  * @param GF_Field[] $fields
1960  * @param array $configured_fields
1961  * @since 1.5
1962  * @return array $fields
1963  */
1964  private function filter_fields( $fields, $configured_fields ) {
1965 
1966  if( empty( $fields ) || !is_array( $fields ) ) {
1967  return $fields;
1968  }
1969 
1970  $edit_fields = array();
1971 
1972  $field_type_blocklist = $this->loader->get_field_blocklist( $this->entry );
1973 
1974  if ( empty( $configured_fields ) && apply_filters( 'gravityview/features/paged-edit', false ) ) {
1975  $field_type_blocklist = array_diff( $field_type_blocklist, array( 'page' ) );
1976  }
1977 
1978  // First, remove blocklist or calculation fields
1979  foreach ( $fields as $key => $field ) {
1980 
1981  // Remove the fields that have calculation properties and keep them to be used later
1982  // @since 1.16.2
1983  if( $field->has_calculation() ) {
1984  $this->fields_with_calculation[] = $field;
1985  // don't remove the calculation fields on form render.
1986  }
1987 
1988  if( in_array( $field->type, $field_type_blocklist ) ) {
1989  unset( $fields[ $key ] );
1990  }
1991  }
1992 
1993  // The Edit tab has not been configured, so we return all fields by default.
1994  // But we do keep the hidden ones hidden please, for everyone :)
1995  if ( empty( $configured_fields ) ) {
1996 
1997  $out_fields = array();
1998 
1999  foreach ( $fields as &$field ) {
2000 
2001  /**
2002  * @filter `gravityview/edit_entry/render_hidden_field`
2003  * @see https://docs.gravityview.co/article/678-edit-entry-hidden-fields-field-visibility
2004  * @since 2.7
2005  * @param bool $render_hidden_field Whether to render this Hidden field in HTML. Default: true
2006  * @param GF_Field $field The field to possibly remove
2007  */
2008  $render_hidden_field = apply_filters( 'gravityview/edit_entry/render_hidden_field', true, $field );
2009 
2010  if ( 'hidden' === $field->type && ! $render_hidden_field ) {
2011  continue; // Don't include hidden fields in the output
2012  }
2013 
2014  if ( 'hidden' == $field->visibility ) {
2015  continue; // Never include when no fields are configured
2016  }
2017 
2018  $out_fields[] = $field;
2019  }
2020 
2021  return array_values( $out_fields );
2022  }
2023 
2024  // The edit tab has been configured, so we loop through to configured settings
2025  foreach ( $configured_fields as $configured_field ) {
2026 
2027  /** @var GF_Field $field */
2028  foreach ( $fields as $field ) {
2029  if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) {
2030  $edit_fields[] = $this->merge_field_properties( $field, $configured_field );
2031  break;
2032  }
2033 
2034  }
2035 
2036  }
2037 
2038  return $edit_fields;
2039 
2040  }
2041 
2042  /**
2043  * Override GF Form field properties with the ones defined on the View
2044  * @param GF_Field $field GF Form field object
2045  * @param array $field_setting GV field options
2046  * @since 1.5
2047  * @return array|GF_Field
2048  */
2049  private function merge_field_properties( $field, $field_setting ) {
2050 
2051  $return_field = $field;
2052 
2053  if( empty( $field_setting['show_label'] ) ) {
2054  $return_field->label = '';
2055  } elseif ( !empty( $field_setting['custom_label'] ) ) {
2056  $return_field->label = $field_setting['custom_label'];
2057  }
2058 
2059  if( !empty( $field_setting['custom_class'] ) ) {
2060  $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] );
2061  }
2062 
2063  /**
2064  * Normalize page numbers - avoid conflicts with page validation
2065  * @since 1.6
2066  */
2067  $return_field->pageNumber = 1;
2068 
2069  return $return_field;
2070 
2071  }
2072 
2073  /**
2074  * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property
2075  *
2076  * @since 1.9.1
2077  *
2078  * @param array|GF_Field[] $fields Gravity Forms form fields
2079  * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration
2080  * @param array $form GF Form array
2081  * @param int $view_id View ID
2082  *
2083  * @return array Possibly modified form array
2084  */
2085  private function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) {
2086 
2087  /**
2088  * @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
2089  * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators.
2090  * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions
2091  * @since 1.9.1
2092  * @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.
2093  * @param array $form GF Form array
2094  * @param int $view_id View ID
2095  */
2096  $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id );
2097 
2098  if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) {
2099  foreach( $fields as $k => $field ) {
2100  if( $field->adminOnly ) {
2101  unset( $fields[ $k ] );
2102  }
2103  }
2104  return array_values( $fields );
2105  }
2106 
2107  foreach( $fields as &$field ) {
2108  $field->adminOnly = false;
2109  }
2110 
2111  return $fields;
2112  }
2113 
2114  /**
2115  * Checkboxes and other checkbox-based controls should not
2116  * display default checks in edit mode.
2117  *
2118  * https://github.com/gravityview/GravityView/1149
2119  *
2120  * @since 2.1
2121  *
2122  * @param array $form Gravity Forms array object
2123  *
2124  * @return array $form, modified to default checkboxes, radios from showing up.
2125  */
2126  private function unselect_default_values( $form ) {
2127 
2128  foreach ( $form['fields'] as &$field ) {
2129 
2130  if ( empty( $field->choices ) ) {
2131  continue;
2132  }
2133 
2134  foreach ( $field->choices as &$choice ) {
2135  if ( \GV\Utils::get( $choice, 'isSelected' ) ) {
2136  $choice['isSelected'] = false;
2137  }
2138  }
2139  }
2140 
2141  return $form;
2142  }
2143 
2144  // --- Conditional Logic
2145 
2146  /**
2147  * Conditional logic isn't designed to work with forms that already have content. When switching input values,
2148  * the dependent fields will be blank.
2149  *
2150  * Note: This is because GF populates a JavaScript variable with the input values. This is tough to filter at the input level;
2151  * via the `gform_field_value` filter; it requires lots of legwork. Doing it at the form level is easier.
2152  *
2153  * @since 1.17.4
2154  *
2155  * @param array $form Gravity Forms array object
2156  *
2157  * @return array $form, modified to fix conditional
2158  */
2159  function prefill_conditional_logic( $form ) {
2160 
2161  if( ! GFFormDisplay::has_conditional_logic( $form ) ) {
2162  return $form;
2163  }
2164 
2165  // Have Conditional Logic pre-fill fields as if the data were default values
2166  /** @var GF_Field $field */
2167  foreach ( $form['fields'] as &$field ) {
2168 
2169  if( 'checkbox' === $field->type ) {
2170  foreach ( $field->get_entry_inputs() as $key => $input ) {
2171  $input_id = $input['id'];
2172  $choice = $field->choices[ $key ];
2173  $value = \GV\Utils::get( $this->entry, $input_id );
2174  $match = RGFormsModel::choice_value_match( $field, $choice, $value );
2175  if( $match ) {
2176  $field->choices[ $key ]['isSelected'] = true;
2177  }
2178  }
2179  } else {
2180 
2181  // We need to run through each field to set the default values
2182  foreach ( $this->entry as $field_id => $field_value ) {
2183 
2184  if( floatval( $field_id ) === floatval( $field->id ) ) {
2185 
2186  if( 'list' === $field->type ) {
2187  $list_rows = maybe_unserialize( $field_value );
2188 
2189  $list_field_value = array();
2190  foreach ( (array) $list_rows as $row ) {
2191  foreach ( (array) $row as $column ) {
2192  $list_field_value[] = $column;
2193  }
2194  }
2195 
2196  $field->defaultValue = serialize( $list_field_value );
2197  } else {
2198  $field->defaultValue = $field_value;
2199  }
2200  }
2201  }
2202  }
2203  }
2204 
2205  return $form;
2206  }
2207 
2208  /**
2209  * Remove the conditional logic rules from the form button and the form fields, if needed.
2210  *
2211  * @todo Merge with caller method
2212  * @since 1.9
2213  *
2214  * @param array $form Gravity Forms form
2215  * @return array Modified form, if not using Conditional Logic
2216  */
2217  private function filter_conditional_logic( $form ) {
2218  /**
2219  * Fields that are tied to a conditional logic field that is not present in the view
2220  * have to still be displayed, if the condition is met.
2221  *
2222  * @see https://github.com/gravityview/GravityView/issues/840
2223  * @since develop
2224  */
2225  $the_form = GFAPI::get_form( $form['id'] );
2226  $editable_ids = array();
2227  foreach ( $form['fields'] as $field ) {
2228  $editable_ids[] = $field['id']; // wp_list_pluck is destructive in this context
2229  }
2230  $remove_conditions_rule = array();
2231  foreach ( $the_form['fields'] as $field ) {
2232  if ( ! empty( $field->conditionalLogic ) && ! empty( $field->conditionalLogic['rules'] ) ) {
2233  foreach ( $field->conditionalLogic['rules'] as $i => $rule ) {
2234  if ( ! in_array( $rule['fieldId'], $editable_ids ) ) {
2235  /**
2236  * This conditional field is not editable in this View.
2237  * We need to remove the rule, but only if it matches.
2238  */
2239  if ( $_field = GFAPI::get_field( $the_form, $rule['fieldId'] ) ) {
2240  $value = $_field->get_value_export( $this->entry );
2241  } elseif ( isset( $this->entry[ $rule['fieldId'] ] ) ) {
2242  $value = $this->entry[ $rule['fieldId'] ];
2243  } else {
2244  $value = gform_get_meta( $this->entry['id'], $rule['fieldId'] );
2245  }
2246 
2247  $match = GFFormsModel::matches_operation( $value, $rule['value'], $rule['operator'] );
2248 
2249  if ( $match ) {
2250  $remove_conditions_rule[] = array( $field['id'], $i );
2251  }
2252  }
2253  }
2254  }
2255  }
2256 
2257  if ( $remove_conditions_rule ) {
2258  foreach ( $form['fields'] as &$field ) {
2259  foreach ( $remove_conditions_rule as $_remove_conditions_r ) {
2260 
2261  list( $rule_field_id, $rule_i ) = $_remove_conditions_r;
2262 
2263  if ( $field['id'] == $rule_field_id ) {
2264  unset( $field->conditionalLogic['rules'][ $rule_i ] );
2265  gravityview()->log->debug( 'Removed conditional rule #{rule} for field {field_id}', array( 'rule' => $rule_i, 'field_id' => $field['id'] ) );
2266  }
2267  }
2268  }
2269  }
2270 
2271  /** Normalize the indices... */
2272  $form['fields'] = array_values( $form['fields'] );
2273 
2274  /**
2275  * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields?
2276  * @since 1.9
2277  * @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
2278  * @param array $form Gravity Forms form
2279  */
2280  $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form );
2281 
2282  if( $use_conditional_logic ) {
2283  return $form;
2284  }
2285 
2286  foreach( $form['fields'] as &$field ) {
2287  /* @var GF_Field $field */
2288  $field->conditionalLogic = null;
2289  }
2290 
2291  unset( $form['button']['conditionalLogic'] );
2292 
2293  return $form;
2294 
2295  }
2296 
2297  /**
2298  * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen
2299  *
2300  * @since 1.9
2301  *
2302  * @param $has_conditional_logic
2303  * @param $form
2304  * @return mixed
2305  */
2306  public function manage_conditional_logic( $has_conditional_logic, $form ) {
2307 
2308  if( ! $this->is_edit_entry() ) {
2309  return $has_conditional_logic;
2310  }
2311 
2312  /** @see GravityView_Edit_Entry_Render::filter_conditional_logic for filter documentation */
2313  return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form );
2314  }
2315 
2316 
2317  // --- User checks and nonces
2318 
2319  /**
2320  * Check if the user can edit the entry
2321  *
2322  * - Is the nonce valid?
2323  * - Does the user have the right caps for the entry
2324  * - Is the entry in the trash?
2325  *
2326  * @todo Move to GVCommon
2327  *
2328  * @param boolean $echo Show error messages in the form?
2329  * @return boolean True: can edit form. False: nope.
2330  */
2331  private function user_can_edit_entry( $echo = false ) {
2332 
2333  $error = NULL;
2334 
2335  /**
2336  * 1. Permalinks are turned off
2337  * 2. There are two entries embedded using oEmbed
2338  * 3. One of the entries has just been saved
2339  */
2340  if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) {
2341 
2342  $error = true;
2343 
2344  }
2345 
2346  if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) {
2347 
2348  $error = true;
2349 
2350  } elseif( ! $this->verify_nonce() ) {
2351 
2352  /**
2353  * If the Entry is embedded, there may be two entries on the same page.
2354  * If that's the case, and one is being edited, the other should fail gracefully and not display an error.
2355  */
2356  if( GravityView_oEmbed::getInstance()->get_entry_id() ) {
2357  $error = true;
2358  } else {
2359  $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gk-gravityview');
2360  }
2361 
2362  }
2363 
2364  if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry, $this->view ) ) {
2365  $error = __( 'You do not have permission to edit this entry.', 'gk-gravityview');
2366  }
2367 
2368  if( $this->entry['status'] === 'trash' ) {
2369  $error = __('You cannot edit the entry; it is in the trash.', 'gk-gravityview' );
2370  }
2371 
2372  // No errors; everything's fine here!
2373  if( empty( $error ) ) {
2374  return true;
2375  }
2376 
2377  if( $echo && $error !== true ) {
2378 
2379  $error = esc_html( $error );
2380 
2381  /**
2382  * @since 1.9
2383  */
2384  if ( ! empty( $this->entry ) ) {
2385  $error .= ' ' . gravityview_get_link( '#', _x('Go back.', 'Link shown when invalid Edit Entry link is clicked', 'gk-gravityview' ), array( 'onclick' => "window.history.go(-1); return false;" ) );
2386  }
2387 
2388  echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error');
2389  }
2390 
2391  gravityview()->log->error( '{error}', array( 'error' => $error ) );
2392 
2393  return false;
2394  }
2395 
2396 
2397  /**
2398  * Check whether a field is editable by the current user, and optionally display an error message
2399  * @uses GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities
2400  * @param array $field Field or field settings array
2401  * @param boolean $echo Whether to show error message telling user they aren't allowed
2402  * @return boolean True: user can edit the current field; False: nope, they can't.
2403  */
2404  private function user_can_edit_field( $field, $echo = false ) {
2405 
2406  $error = NULL;
2407 
2408  if( ! $this->check_user_cap_edit_field( $field ) ) {
2409  $error = __( 'You do not have permission to edit this field.', 'gk-gravityview');
2410  }
2411 
2412  // No errors; everything's fine here!
2413  if( empty( $error ) ) {
2414  return true;
2415  }
2416 
2417  if( $echo ) {
2418  echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error');
2419  }
2420 
2421  gravityview()->log->error( '{error}', array( 'error' => $error ) );
2422 
2423  return false;
2424 
2425  }
2426 
2427 
2428  /**
2429  * checks if user has permissions to edit a specific field
2430  *
2431  * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!!
2432  *
2433  * @param [type] $field [description]
2434  * @return bool
2435  */
2436  private function check_user_cap_edit_field( $field ) {
2437 
2438  // If they can edit any entries (as defined in Gravity Forms), we're good.
2439  if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) {
2440  return true;
2441  }
2442 
2443  $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false;
2444 
2445  if( $field_cap ) {
2446  return GVCommon::has_cap( $field['allow_edit_cap'] );
2447  }
2448 
2449  return false;
2450  }
2451 
2452 
2453  /**
2454  * Is the current nonce valid for editing the entry?
2455  * @return boolean
2456  */
2457  public function verify_nonce() {
2458 
2459  // Verify form submitted for editing single
2460  if( $this->is_edit_entry_submission() ) {
2461  $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field );
2462  }
2463 
2464  // Verify
2465  else if( ! $this->is_edit_entry() ) {
2466  $valid = false;
2467  }
2468 
2469  else {
2470  $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key );
2471  }
2472 
2473  /**
2474  * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid.
2475  * @since 1.13
2476  * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated
2477  * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry
2478  */
2479  $valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field );
2480 
2481  return $valid;
2482  }
2483 
2484 
2485  /**
2486  * Multiselect in GF 2.2 became a json_encoded value. Fix it.
2487  *
2488  * As a hack for now we'll implode it back.
2489  */
2491  if ( empty ( $field->storageType ) || $field->storageType != 'json' ) {
2492  return $field_value;
2493  }
2494 
2495  $maybe_json = @json_decode( $field_value, true );
2496 
2497  if ( $maybe_json ) {
2498  return implode( ',', $maybe_json );
2499  }
2500 
2501  return $field_value;
2502  }
2503 
2504  /**
2505  * Returns labels for the action links on Edit Entry
2506  *
2507  * @since 2.10.4
2508  *
2509  * @return array `cancel`, `submit`, `next`, `previous` array keys with associated labels.
2510  */
2511  public function get_action_labels() {
2512 
2513  $labels = array(
2514  'cancel' => $this->view->settings->get( 'action_label_cancel', _x( 'Cancel', 'Shown when the user decides not to edit an entry', 'gk-gravityview' ) ),
2515  'submit' => $this->view->settings->get( 'action_label_update', _x( 'Update', 'Button to update an entry the user is editing', 'gk-gravityview' ) ),
2516  'next' => $this->view->settings->get( 'action_label_next', __( 'Next', 'Show the next page in a multi-page form', 'gk-gravityview' ) ),
2517  'previous' => $this->view->settings->get( 'action_label_previous', __( 'Previous', 'Show the previous page in a multi-page form', 'gk-gravityview' ) ),
2518  );
2519 
2520  /**
2521  * @filter `gravityview/edit_entry/button_labels` Modify the cancel/submit buttons' labels
2522  * @since 1.16.3
2523  * @param array $labels Default button labels associative array
2524  * @param array $form The Gravity Forms form
2525  * @param array $entry The Gravity Forms entry
2526  * @param int $view_id The current View ID
2527  */
2528  $labels = apply_filters( 'gravityview/edit_entry/button_labels', $labels, $this->form, $this->entry, $this->view_id );
2529 
2530  return (array) $labels;
2531  }
2532 
2533 } //end class
get_configured_edit_fields( $form, $view_id)
Get the Edit Entry fields as configured in the View.
const GRAVITYVIEW_DIR
"GRAVITYVIEW_DIR" "./" The absolute path to the plugin directory, with trailing slash ...
Definition: gravityview.php:49
$labels
$entry
if(current_filter()==='gform_previous_button') if(current_filter()==='gform_next_button') $back_link
static media_handle_upload( $url, $post_id, $post_data=array())
Copied function from Gravity Forms plugin ::media_handle_upload since the method is private...
static getInstance( $passed_post=NULL)
edit_entry_form()
Display the Edit Entry form.
$fields_with_calculation
$image_meta
Definition: post_image.php:106
static getInstance( $passed_post=NULL)
Definition: class-data.php:122
fill_post_template( $template, $form, $entry, $do_shortcode=false)
Convert a field content template into prepared output.
if(! function_exists( 'gravityview_sanitize_html_class')) gravityview_strip_whitespace( $string)
Replace multiple newlines, tabs, and spaces with a single space.
load()
if(! isset( $gravityview)||empty( $gravityview->template)) $template
The entry loop for the list output.
update_calculation_fields()
$is_valid
filter_conditional_logic( $form)
Remove the conditional logic rules from the form button and the form fields, if needed.
is_edit_entry()
Is the current page an Edit Entry page?
static get_post_field_images( $form, $entry)
Given information provided in an entry, get array of media IDs.
$ary
Definition: post_image.php:24
render_edit_form()
Display the Edit Entry form in the original Gravity Forms format.
static check_user_cap_edit_entry( $entry, $view=0)
checks if user has permissions to edit a specific entry
static generate_notice( $notice, $class='', $cap='', $object_id=null)
Display updated/error notice.
process_save_process_files( $form_id)
Have GF handle file uploads.
$entries
gravityview_get_link( $href='', $anchor_text='', $atts=array())
Generate an HTML anchor tag with a list of supported attributes.
gravityview_get_entry( $entry_slug, $force_allow_ids=false, $check_entry_display=true, $view=null)
Return a single entry object.
setup_vars( $view, $entry)
When Edit entry view is requested, set up key class variables.
save_field_value( $value='', $entry=array(), $field=null, $form=array(), $input_id='')
Make sure the fileuploads are not overwritten if no such request was done.
after_update()
Perform actions normally performed after updating a lead.
global $post
Definition: delete-entry.php:7
If this file is called directly, abort.
form_prepare_for_save()
Set visibility to visible and convert field input key to string.
static $nonce_field
maybe_print_message()
Display success or error message if the form has been submitted.
$show_next_button
static directory_link( $post_id=NULL, $add_query_args=true, $context=null)
Generate a URL to the Directory context.
Definition: class-api.php:399
unset_hidden_field_values()
Delete the value of fields hidden by conditional logic when the entry is edited.
gravityview_ob_include( $file_path, $object=NULL)
Get the contents of a file using include() and ob_start()
$view_id
gform_pre_validation( $form)
Add field keys that Gravity Forms expects.
update_post_image( $form, $field, $field_id, $value, $entry, $post_id)
Handle updating the Post Image field.
static $nonce_key
process_save( $gv_data)
Process edit entry form save.
print_scripts()
Force Gravity Forms to output scripts as if it were in the admin.
manage_conditional_logic( $has_conditional_logic, $form)
Disable the Gravity Forms conditional logic script and features on the Edit Entry screen...
$form_id
check_user_cap_edit_field( $field)
checks if user has permissions to edit a specific field
prevent_update_unapproved_meta( $value, $form, $entry)
Done once from self::preset_approval_fields.
$gv_field
Definition: time.php:11
__construct(GravityView_Edit_Entry $loader)
static get_associated_field( $gf_field)
Alias for get_instance()
user_can_edit_field( $field, $echo=false)
Check whether a field is editable by the current user, and optionally display an error message Gravi...
static by_id( $post_id)
Construct a instance from a post ID.
static get_nonce_key( $view_id, $form_id, $entry_id)
Return a well formatted nonce key according to GravityView Edit Entry protocol.
static $original_form
merge_field_properties( $field, $field_setting)
Override GF Form field properties with the ones defined on the View.
prevent_maybe_process_form()
Because we&#39;re mimicking being a front-end Gravity Forms form while using a Gravity Forms backend form...
static $file
get_field_value( $field)
Modify the value for the current field input.
verify_user_can_edit_post( $field_content='', $field=null, $value='', $lead_id=0, $form_id=0)
When displaying a field, check if it&#39;s a Post Field, and if so, make sure the post exists and current...
modify_fileupload_settings( $plupload_init, $form_id, $instance)
Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView Late valida...
static is_single_entry()
Verify if user requested a single entry view.
static $original_entry
static $supports_save_and_continue
$is_paged_submitted
validate()
Process validation for a edit entry submission.
verify_nonce()
Is the current nonce valid for editing the entry?
get_entry()
TODO: This seems to be hacky...
const UNAPPROVED
render_form_buttons()
Display the Update/Cancel/Delete buttons for the Edit Entry form.
filter_modify_form_fields( $form, $ajax=false, $field_values='')
Modify the form fields that are shown when using GFFormDisplay::get_form()
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
gravityview()
The main GravityView wrapper function.
is_edit_entry_submission()
Is the current page an Edit Entry page?
preset_approval_fields()
Leverage gravityview/approve_entries/update_unapproved_meta to prevent the missing/empty approval fie...
static get_database_version()
Make sure the method exists, regardless of GF version.
$form_after_validation
gv_empty( $value, $zero_is_empty=true, $allow_string_booleans=true)
Is the value empty?
$post_id
$view
init( $gv_data=null, $entry=null, $view=null, $request=null)
Load required files and trigger edit flow.
static has_cap( $caps='', $object_id=null, $user_id=null)
Alias of GravityView_Roles_Capabilities::has_cap()
maybe_update_post_fields( $form)
Loop through the fields being edited and if they include Post fields, update the Entry&#39;s post object...
$loader
user_can_edit_entry( $echo=false)
Check if the user can edit the entry.
$form
if(false !==strpos( $value, '00:00')) $field_id
string $field_id ID of the field being displayed
Definition: time.php:22
get_action_labels()
Returns labels for the action links on Edit Entry.
$show_update_button
custom_validation( $validation_results)
Make validation work for Edit Entry.
fix_multiselect_value_serialization( $field_value, $field, $_this)
Multiselect in GF 2.2 became a json_encoded value.
filter_admin_only_fields( $fields=array(), $edit_fields=null, $form=array(), $view_id=0)
Remove fields that shouldn&#39;t be visible based on the Gravity Forms adminOnly field property...
prevent_render_form()
Don&#39;t show any forms embedded on a page when GravityView is in Edit Entry mode.
$field_value
Definition: checkbox.php:24
static _POST( $name, $default=null)
Grab a value from the _POST superglobal or default.
unselect_default_values( $form)
Checkboxes and other checkbox-based controls should not display default checks in edit mode...
$show_previous_button