12 if ( ! defined(
'WPINC' ) ) {
138 include_once(
GRAVITYVIEW_DIR .
'includes/class-admin-approve-entries.php' );
141 add_action(
'wp_head', array( $this,
'prevent_render_form' ) );
142 add_action(
'wp_footer', array( $this,
'prevent_render_form' ) );
145 add_action(
'wp', array( $this,
'prevent_maybe_process_form' ), 8 );
146 add_action(
'admin_init', array( $this,
'prevent_maybe_process_form' ), 8 );
148 add_filter(
'gravityview_is_edit_entry', array( $this,
'is_edit_entry') );
150 add_action(
'gravityview_edit_entry', array( $this,
'init' ), 10, 4 );
153 add_filter(
'gform_has_conditional_logic', array( $this,
'manage_conditional_logic' ), 10, 2 );
156 add_filter(
'gform_plupload_settings', array( $this,
'modify_fileupload_settings' ), 10, 3 );
159 add_filter(
'gform_pre_validation', array( $this,
'gform_pre_validation') );
162 add_filter(
'gravityview/edit_entry/field_value_multiselect', array( $this,
'fix_multiselect_value_serialization' ), 10, 3 );
177 if(
'wp_head' === current_filter() ) {
178 add_filter(
'gform_shortcode_form',
'__return_empty_string' );
180 remove_filter(
'gform_shortcode_form',
'__return_empty_string' );
196 gravityview()->log->debug(
'GravityView_Edit_Entry[prevent_maybe_process_form] Removing GFForms::maybe_process_form() action.' );
198 remove_action(
'wp', array(
'RGForms',
'maybe_process_form'), 9 );
199 remove_action(
'wp', array(
'GFForms',
'maybe_process_form'), 9 );
201 remove_action(
'admin_init', array(
'GFForms',
'maybe_process_form'), 9 );
202 remove_action(
'admin_init', array(
'RGForms',
'maybe_process_form'), 9 );
213 && ( ! empty( $_GET[
'edit'] ) );
224 return !empty( $_POST[ self::$nonce_field ] );
241 self::$original_entry =
$entry->as_entry();
242 $this->entry =
$entry->as_entry();
246 self::$original_entry =
$entries[0];
250 self::$original_form = GFAPI::get_form( $this->entry[
'form_id'] );
251 $this->form = self::$original_form;
253 $this->form_id = $this->entry[
'form_id'];
278 public function init( $gv_data = null,
$entry = null,
$view = null, $request = null ) {
280 require_once( GFCommon::get_base_path() .
'/form_display.php' );
281 require_once( GFCommon::get_base_path() .
'/entry_detail.php' );
289 if (
$view && ! $gv_data->views->count() ) {
290 $gv_data->views->add(
$view );
294 if ( $gv_data->has_multiple_views() && ! $this->
verify_nonce() ) {
295 gravityview()->log->error(
'Nonce validation failed for the Edit Entry request; returning' );
301 gravityview()->log->error(
'User is not allowed to edit this entry; returning', array(
'data' => $this->entry ) );
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' ) );
323 GFFormDisplay::enqueue_form_scripts( $this->form ? $this->form :
$gravityview_view->getForm(), false );
325 wp_localize_script(
'gravityview-fe-view',
'gvGlobals', array(
'cookiepath' => COOKIEPATH ) );
327 wp_enqueue_script(
'sack');
328 wp_enqueue_script(
'gform_gravityforms');
329 wp_enqueue_script(
'gravityview-fe-view');
332 wp_enqueue_style(
'gform_admin_icons' );
343 if ( empty( $_POST ) || ! isset( $_POST[
'lid'] ) ) {
351 gravityview()->log->error(
'Nonce validation failed.' );
355 if ( $this->entry[
'id'] !== $_POST[
'lid'] ) {
356 gravityview()->log->error(
'Entry ID did not match posted entry ID.' );
360 gravityview()->log->debug(
'$_POSTed data (sanitized): ', array(
'data' => esc_html( print_r( $_POST,
true ) ) ) );
366 if( $this->is_valid ) {
368 gravityview()->log->debug(
'Submission is valid.' );
378 unset( $_GET[
'page'] );
380 add_filter(
'gform_use_post_value_for_conditional_logic_save_entry',
'__return_true' );
390 do_action(
'gravityview/edit_entry/before_update',
$form, $this->entry[
'id'], $this, $gv_data );
392 GFFormsModel::save_lead(
$form, $this->entry );
420 do_action(
'gravityview/edit_entry/after_update', $this->form, $this->entry[
'id'], $this, $gv_data );
423 gravityview()->log->error(
'Submission is NOT valid.', array(
'entry' => $this->entry ) );
446 $unset_hidden_field_values = apply_filters(
'gravityview/edit_entry/unset_hidden_field_values',
true, $this );
448 $this->unset_hidden_calculations = array();
450 if ( ! $unset_hidden_field_values ) {
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'] ) );
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'] ) );
473 if ( GFFormsModel::is_field_hidden( $this->form,
$field, array(), $this->entry ) ) {
475 $empty_value =
$field->get_value_save_entry(
476 is_array(
$field->get_entry_inputs() ) ? array() :
'',
480 if (
$field->has_calculation() ) {
481 $this->unset_hidden_calculations[] =
$field->id;
485 $lead_detail_id = GFFormsModel::get_lead_detail_id( $current_fields,
$input_id );
487 GFFormsModel::update_lead_field_value( $this->form, $this->entry,
$field, $lead_detail_id,
$input_id, $empty_value );
491 $post_input_id =
'input_' . str_replace(
'.',
'_',
$input_id );
492 $_POST[ $post_input_id ] =
'';
508 $has_approved_field =
false;
510 foreach ( self::$original_form[
'fields'] as
$field ) {
511 if ( $field->gravityview_approved ) {
512 $has_approved_field =
true;
517 if ( ! $has_approved_field ) {
521 $is_field_hidden =
true;
523 foreach ( $this->form[
'fields'] as $field ) {
524 if ( $field->gravityview_approved ) {
525 $is_field_hidden =
false;
530 if ( ! $is_field_hidden ) {
534 add_filter(
'gravityview/approve_entries/update_unapproved_meta', array( $this,
'prevent_update_unapproved_meta' ), 9, 3 );
546 remove_filter(
'gravityview/approve_entries/update_unapproved_meta', array( $this,
'prevent_update_unapproved_meta' ), 9 );
548 if ( !
$value = gform_get_meta(
$entry[
'id'],
'is_approved' ) ) {
552 $value = apply_filters(
'gravityview/approve_entries/after_submission/default_status',
$value );
568 $files = GFCommon::json_decode( stripslashes( RGForms::post(
'gform_uploaded_files' ) ) );
569 if ( ! is_array( $files ) ) {
577 add_filter(
"gform_save_field_value_$form_id", array( $this,
'save_field_value' ), 99, 5 );
579 RGFormsModel::$uploaded_files[
$form_id ] = $files;
603 $input_name =
'input_' . str_replace(
'.',
'_',
$input_id );
605 if (
$field->multipleFiles ) {
613 if ( empty( $_FILES[ $input_name ][
'name'] ) ) {
632 return $plupload_init;
635 $plupload_init[
'gf_vars'][
'max_files'] = 0;
637 return $plupload_init;
656 if(
$field->has_calculation() ) {
657 unset(
$form[
'fields'][ $k ] );
660 $field->adminOnly =
false;
662 if( isset(
$field->inputs ) && is_array(
$field->inputs ) ) {
663 foreach(
$field->inputs as $key => $input ) {
664 $field->inputs[ $key ][
'id' ] = (string)$input[
'id'];
669 $form[
'fields'] = array_values(
$form[
'fields'] );
677 $form = self::$original_form;
681 $entry = GFAPI::get_entry( $this->entry[
'id'] );
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'] ) );
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'] ) );
692 if ( ! empty( $this->fields_with_calculation ) ) {
694 $allowed_fields = wp_list_pluck( $allowed_fields,
'id' );
696 foreach ( $this->fields_with_calculation as
$field ) {
698 if ( in_array( $field->id, $this->unset_hidden_calculations,
true ) ) {
702 $inputs = $field->get_entry_inputs();
703 if ( is_array( $inputs ) ) {
704 foreach ( $inputs as $input ) {
707 if (
'product' === $field->type ) {
708 $input_name =
'input_' . str_replace(
'.',
'_', $input[
'id'] );
713 $_POST[ $input_name ] =
$entry[ $input[
'id'] ];
717 if ( ! in_array(
$field_id, $allowed_fields ) ) {
718 $_POST[ $input_name ] =
$entry[ $input[
'id'] ];
722 GFFormsModel::save_input(
$form, $field,
$entry, $current_fields, $input[
'id'] );
726 if ( ! in_array( $field->id, $allowed_fields ) ) {
727 $_POST[
'input_' . $field->id ] =
$entry[ $field->id ];
729 GFFormsModel::save_input(
$form, $field,
$entry, $current_fields, $field->id );
733 if ( method_exists(
'GFFormsModel',
'commit_batch_field_operations' ) ) {
734 GFFormsModel::commit_batch_field_operations();
762 if ( !empty( $_FILES[ $input_name ][
'name'] ) ) {
772 $img_title = count(
$ary ) > 1 ?
$ary[1] :
'';
773 $img_caption = count(
$ary ) > 2 ?
$ary[2] :
'';
774 $img_description = count(
$ary ) > 3 ?
$ary[3] :
'';
777 'post_excerpt' => $img_caption,
778 'post_content' => $img_description,
782 if ( ! empty( $img_title ) ) {
790 require_once
GRAVITYVIEW_DIR .
'includes/class-gravityview-gfformsmodel.php';
794 if ( $media_id &&
$field->postFeaturedImage ) {
795 set_post_thumbnail(
$post_id, $media_id );
798 } elseif ( ! empty( $_POST[ $input_name ] ) && is_array(
$value ) ) {
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' ) );
805 $value = ! empty( $img_url ) ? $img_url .
"|:|" . $img_title .
"|:|" . $img_caption .
"|:|" . $img_description :
'';
807 if (
$field->postFeaturedImage ) {
810 'ID' => get_post_thumbnail_id(
$post_id ),
811 'post_title' => $img_title,
812 'post_excerpt' => $img_caption,
813 'post_content' => $img_description,
824 if (
$field->postFeaturedImage ) {
841 if( empty( $this->entry[
'post_id'] ) ) {
842 gravityview()->log->debug(
'This entry has no post fields. Continuing...' );
850 gravityview()->log->error(
'The current user does not have the ability to edit Post #{post_id}', array(
'post_id' =>
$post_id ) );
854 $update_entry =
false;
856 $updated_post = $original_post = get_post(
$post_id );
866 if( GFCommon::is_post_field(
$field ) &&
'post_category' !==
$field->type ) {
873 $entry_tmp[
"{$field_id}"] =
$value;
879 if ( \
GV\Utils::get(
$form,
'postTitleTemplateEnabled' ) ) {
882 $updated_post->post_title = $post_title;
883 $updated_post->post_name = $post_title;
884 unset( $post_title );
889 if ( \
GV\Utils::get(
$form,
'postContentTemplateEnabled' ) ) {
892 $updated_post->post_content = $post_content;
893 unset( $post_content );
896 $updated_post->post_excerpt =
$value;
901 case 'post_category':
903 case 'post_custom_field':
908 if( ! empty(
$field->customFieldTemplateEnabled ) ) {
924 $this->entry[
"{$field_id}"] =
$value;
926 $update_entry =
true;
933 if( $update_entry ) {
935 $return_entry = GFAPI::update_entry( $this->entry );
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 ) ) );
940 gravityview()->log->debug(
'Updating the entry post fields for post #{post_id} succeeded', array(
'post_id' =>
$post_id ) );
945 $return_post = wp_update_post( $updated_post,
true );
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' ) ) );
951 gravityview()->log->debug(
'Updating the post content for post #{post_id} succeeded', array(
'post_id' =>
$post_id,
'data' => $updated_post ) );
970 require_once
GRAVITYVIEW_DIR .
'includes/class-gravityview-gfformsmodel.php';
981 if( $do_shortcode ) {
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 );
1004 $entry = RGFormsModel::get_lead( $this->entry[
'id'] );
1006 $entry = GFFormsModel::set_entry_meta(
$entry, self::$original_form );
1008 if ( version_compare( GFFormsModel::get_database_version(),
'2.3-dev-1',
'<' ) ) {
1011 foreach ($this->form[
'fields'] as $key =>
$field) {
1012 GFFormsModel::refresh_lead_field_value(
$entry[
'id'],
$field->id );
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;
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;
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 );
1063 if(
$view->settings->get(
'edit_locking' ) ) {
1065 $locking->maybe_lock_object( $this->entry[
'id'] );
1070 <div
id=
"wpfooter"></div><!-- used
for locking message -->
1073 var ajaxurl =
'<?php echo admin_url( 'admin-ajax.php
', 'relative
' ); ?>';
1076 <div
class=
"gv-edit-entry-wrapper"><?php
1086 ?><h2
class=
"gv-edit-entry-title">
1094 $edit_entry_title = apply_filters(
'gravityview_edit_entry_title', __(
'Edit Entry',
'gk-gravityview'), $this );
1096 echo esc_attr( $edit_entry_title );
1104 <form method=
"post" id=
"gform_<?php echo $this->form_id; ?>" enctype=
"multipart/form-data">
1108 wp_nonce_field( self::$nonce_key, self::$nonce_key );
1110 wp_nonce_field( self::$nonce_field, self::$nonce_field,
false );
1119 gform.addFilter(
'gform_reset_pre_conditional_logic_field_action',
function ( reset, formId, targetId, defaultValues, isInit ) {
1140 if ( \
GV\Utils::_POST(
'action' ) !==
'update' ) {
1151 $enable_paged_edit = apply_filters(
'gravityview/features/paged-edit',
false, $this->form );
1153 if ( GFCommon::has_pages( $this->form ) && $enable_paged_edit ) {
1155 'cancel' => __(
'Cancel',
'gk-gravityview' ),
1156 'submit' => __(
'Update',
'gk-gravityview' ),
1157 'next' => __(
'Next',
'gk-gravityview' ),
1158 'previous' => __(
'Previous',
'gk-gravityview' ),
1169 $labels = apply_filters(
'gravityview/edit_entry/button_labels',
$labels, $this->form, $this->entry, $this->view_id );
1174 $back_link = remove_query_arg( array(
'page',
'view',
'edit',
'gvid' ) );
1176 if( ! $this->is_valid ){
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);
1184 } elseif (
false === $this->is_paged_submitted ) {
1186 $entry_updated_message = sprintf( esc_attr__(
'Entry Updated.',
'gk-gravityview' ),
'<a href="' . esc_url(
$back_link ) .
'">',
'</a>' );
1195 $message = apply_filters(
'gravityview/edit_entry/page/success', $entry_updated_message , $this->view_id, $this->entry );
1200 $edit_redirect =
$view->settings->get(
'edit_redirect' );
1201 $edit_redirect_url =
$view->settings->get(
'edit_redirect_url' );
1203 switch ( $edit_redirect ) {
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>' );
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>' );
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>' );
1223 $entry_updated_message = sprintf( esc_attr__(
'Entry Updated. %sReturn to Entry%s',
'gk-gravityview'),
'<a href="'. esc_url(
$back_link ) .
'">',
'</a>' );
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 ) );
1242 $message = apply_filters(
'gravityview/edit_entry/success', $entry_updated_message, $this->view_id, $this->entry,
$back_link, isset( $redirect_url ) ? $redirect_url : null );
1262 do_action(
'gravityview/edit-entry/render/before', $this );
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' );
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 );
1274 unset( $_GET[
'page'] );
1276 $this->show_next_button =
false;
1277 $this->show_previous_button =
false;
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 ) ) ) {
1284 'cancel' => __(
'Cancel',
'gk-gravityview' ),
1285 'submit' => __(
'Update',
'gk-gravityview' ),
1286 'next' => __(
'Next',
'gk-gravityview' ),
1287 'previous' => __(
'Previous',
'gk-gravityview' ),
1298 $labels = apply_filters(
'gravityview/edit_entry/button_labels',
$labels, $this->form, $this->entry, $this->view_id );
1300 GFFormDisplay::$submission[ $this->form[
'id'] ][
'form' ] =
$this->form;
1301 GFFormDisplay::$submission[ $this->form[
'id'] ][
'is_valid' ] =
true;
1303 if ( \
GV\Utils::_POST(
'save' ) ===
$labels[
'next'] ) {
1304 $last_page = \GFFormDisplay::get_max_page_number( $this->form );
1306 while ( ++$page_number < $last_page && RGFormsModel::is_page_hidden( $this->form, $page_number, \
GV\Utils::_POST(
'gform_field_values' ) ) ) {
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' ) ) ) {
1313 GFFormDisplay::$submission[ $this->form[
'id'] ][
'page_number'] = $page_number;
1316 if ( ( $page_number = intval( $page_number ) ) < 2 ) {
1317 $this->show_next_button =
true;
1320 $last_page = \GFFormDisplay::get_max_page_number( $this->form );
1322 $has_more_pages = $page_number < $last_page;
1324 if ( $has_more_pages ) {
1325 $this->show_next_button =
true;
1327 $this->show_update_button =
true;
1330 if ( $page_number > 1 ) {
1331 $this->show_previous_button =
true;
1334 $this->show_update_button =
true;
1339 $html = GFFormDisplay::get_form( $this->form[
'id'],
false,
false,
true, $this->entry );
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 );
1358 do_action(
'gravityview/edit-entry/render/after', $this );
1386 if(
$form[
'id'] != $this->form_id ) {
1391 if( isset( $this->form_after_validation ) && $this->form_after_validation[
'id'] ===
$form[
'id'] ) {
1399 $form = $this->prefill_conditional_logic(
$form );
1402 if( ! self::$supports_save_and_continue ) {
1403 unset(
$form[
'save'] );
1426 if( ! GFCommon::is_post_field(
$field ) ) {
1427 return $field_content;
1433 if( null === get_post( $this->entry[
'post_id'] ) ) {
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'] ) ) {
1444 $message = apply_filters(
'gravityview/edit_entry/unsupported_post_field_text', __(
'You don’t have permission to edit this post.',
'gk-gravityview') );
1448 $field_content = sprintf(
'<div class="ginput_container ginput_container_' .
$field->type .
'">%s</div>', wpautop( $message ) );
1451 return $field_content;
1466 public function modify_edit_field_input( $field_content =
'',
$field = null,
$value =
'', $lead_id = 0,
$form_id = 0 ) {
1475 && ! GFCommon::is_product_field(
$field->type )
1476 || ! empty( $field_content )
1477 || in_array(
$field->type, array(
'honeypot' ) )
1479 return $field_content;
1483 $field->adminOnly =
false;
1500 $warnings = ob_get_clean();
1502 if( !empty( $warnings ) ) {
1524 $override_saved_value = apply_filters(
'gravityview/edit_entry/pre_populate/override',
false,
$field );
1527 if( isset(
$field->inputs ) && is_array(
$field->inputs ) && !in_array(
$field->type, array(
'time',
'date' ) ) ) {
1532 $allow_pre_populated =
$field->allowsPrepopulate;
1534 foreach ( (array)
$field->inputs as $input ) {
1538 if ( isset( $this->entry[
$input_id ] ) && !
gv_empty( $this->entry[ $input_id ],
false,
false ) ) {
1540 $allow_pre_populated =
false;
1545 $pre_value =
$field->get_value_submission( array(),
false );
1551 $id = intval(
$field->id );
1554 $pre_value =
$field->allowsPrepopulate ? GFFormsModel::get_parameter_value(
$field->inputName, array(),
$field ) :
'';
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;
1562 $categories = array();
1563 foreach ( explode(
',',
$field_value ) as $cat_string ) {
1564 $categories[] = GFCommon::format_post_category( $cat_string,
true );
1566 $field_value =
'multiselect' ===
$field->get_input_type() ? $categories : implode(
'', $categories );
1618 foreach ( array(
'noDuplicates',
'adminOnly',
'inputType',
'isRequired',
'enablePrice',
'inputs',
'allowedExtensions' ) as $key ) {
1619 $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL;
1622 switch( RGFormsModel::get_input_type(
$field ) ) {
1636 $input_name =
'input_'.$field->id;
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'];
1655 $_FILES[ $input_name ] = array(
'name' =>
'',
'size' =>
'' );
1659 if ( \
GV\Utils::get(
$field,
'multipleFiles' ) ) {
1662 if ( isset( GFFormsModel::$uploaded_files[
$form_id ][ $input_name ] ) ) {
1666 }
else if ( GFCommon::is_json(
$value ) ) {
1668 global $_gf_uploaded_files;
1670 $_gf_uploaded_files[ $input_name ] =
$value;
1675 GFFormsModel::$uploaded_files[
$form_id ][ $input_name ] =
$value;
1678 $this->entry[ $input_name ] =
$value;
1679 $_POST[ $input_name ] =
$value;
1685 if( !isset( $_POST[
'input_'.
$field->id ] ) ) {
1686 $_POST[
'input_'.$field->id ] = NULL;
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' ) );
1723 add_filter(
'gform_validation_'. $this->form_id, array( $this,
'custom_validation' ), 10, 4);
1726 $failed_validation_page = NULL;
1727 $field_values = RGForms::post(
'gform_field_values' );
1731 unset( $this->form[
'limitEntries'], $this->form[
'scheduleForm'] );
1736 $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page );
1738 remove_filter(
'gform_validation_'. $this->form_id, array( $this,
'custom_validation' ), 10 );
1760 gravityview()->log->debug(
'GravityView_Edit_Entry[custom_validation] Validation results: ', array(
'data' => $validation_results ) );
1762 gravityview()->log->debug(
'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', array(
'data' => esc_html( print_r( $_POST,
true ) ) ) );
1766 foreach ( $validation_results[
'form'][
'fields'] as $key => &
$field ) {
1768 $field_type = RGFormsModel::get_input_type(
$field );
1769 $is_required = ! empty(
$field->isRequired );
1770 $failed_validation = ! empty(
$field->failed_validation );
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' );
1781 switch ( $field_type ) {
1785 if ( $is_required && $failed_validation && ! empty(
$value ) ) {
1786 $field->failed_validation =
false;
1788 unset(
$field->validation_message );
1795 if ( \
GV\Utils::get(
$field,
'maxFiles' ) && \
GV\Utils::get(
$field,
'multipleFiles' ) ) {
1796 $input_name =
'input_' .
$field->id;
1798 $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results[
'form'][
'id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results[
'form'][
'id'] ][ $input_name ] : array();
1808 $count_files = ( is_array( $file_names ) ? count( $file_names ) : 0 ) +
1811 if ( $count_files >
$field->maxFiles ) {
1812 $field->validation_message = __(
'Maximum number of files reached',
'gk-gravityview' );
1813 $field->failed_validation =
true;
1817 GFFormsModel::$uploaded_files[ $validation_results[
'form'][
'id'] ] = null;
1825 if( !empty(
$field->failed_validation ) ) {
1827 gravityview()->log->debug(
'GravityView_Edit_Entry[custom_validation] Field is invalid.', array(
'data' => array(
'field' =>
$field,
'value' =>
$value ) ) );
1829 switch ( $field_type ) {
1836 $field->failed_validation =
false;
1837 unset(
$field->validation_message );
1843 if( empty(
$field->failed_validation ) ) {
1849 if( !empty(
$field->noDuplicates ) ) {
1857 $field->failed_validation =
false;
1859 unset(
$field->validation_message );
1861 gravityview()->log->debug(
'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', array(
'data' =>
$entry ) );
1868 if( GFFormDisplay::is_empty(
$field, $this->form_id ) && empty(
$field->isRequired ) ) {
1869 unset(
$field->validation_message );
1870 $field->failed_validation =
false;
1880 $validation_results[
'is_valid'] = $gv_valid;
1882 gravityview()->log->debug(
'GravityView_Edit_Entry[custom_validation] Validation results.', array(
'data' => $validation_results ) );
1885 $this->form_after_validation = $validation_results[
'form'];
1887 return $validation_results;
1898 if( empty( $this->entry ) ) {
1924 $properties =
$view->fields ?
$view->fields->as_configuration() : array();
1930 $edit_fields = !empty( $properties[
'edit_edit-fields'] ) ? $properties[
'edit_edit-fields'] : NULL;
1933 $fields = $this->filter_fields(
$form[
'fields'], $edit_fields );
1946 $fields = apply_filters(
'gravityview/edit_entry/form_fields', $fields, $edit_fields,
$form,
$view_id );
1964 private function filter_fields( $fields, $configured_fields ) {
1966 if( empty( $fields ) || !is_array( $fields ) ) {
1970 $edit_fields = array();
1972 $field_type_blocklist = $this->loader->get_field_blocklist( $this->entry );
1974 if ( empty( $configured_fields ) && apply_filters(
'gravityview/features/paged-edit',
false ) ) {
1975 $field_type_blocklist = array_diff( $field_type_blocklist, array(
'page' ) );
1979 foreach ( $fields as $key =>
$field ) {
1983 if(
$field->has_calculation() ) {
1984 $this->fields_with_calculation[] =
$field;
1988 if( in_array(
$field->type, $field_type_blocklist ) ) {
1989 unset( $fields[ $key ] );
1995 if ( empty( $configured_fields ) ) {
1997 $out_fields = array();
1999 foreach ( $fields as &
$field ) {
2008 $render_hidden_field = apply_filters(
'gravityview/edit_entry/render_hidden_field',
true, $field );
2010 if (
'hidden' === $field->type && ! $render_hidden_field ) {
2014 if (
'hidden' == $field->visibility ) {
2021 return array_values( $out_fields );
2025 foreach ( $configured_fields as $configured_field ) {
2028 foreach ( $fields as
$field ) {
2029 if( intval( $configured_field[
'id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field,
false ) ) {
2038 return $edit_fields;
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'];
2059 if( !empty( $field_setting[
'custom_class'] ) ) {
2060 $return_field->cssClass .=
' '. gravityview_sanitize_html_class( $field_setting[
'custom_class'] );
2067 $return_field->pageNumber = 1;
2069 return $return_field;
2096 $use_gf_adminonly_setting = apply_filters(
'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ),
$form,
$view_id );
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 ] );
2104 return array_values( $fields );
2107 foreach( $fields as &
$field ) {
2108 $field->adminOnly =
false;
2130 if ( empty( $field->choices ) ) {
2134 foreach ( $field->choices as &$choice ) {
2135 if ( \
GV\Utils::get( $choice,
'isSelected' ) ) {
2136 $choice[
'isSelected'] =
false;
2159 function prefill_conditional_logic(
$form ) {
2161 if( ! GFFormDisplay::has_conditional_logic(
$form ) ) {
2169 if(
'checkbox' === $field->type ) {
2170 foreach ( $field->get_entry_inputs() as $key => $input ) {
2172 $choice = $field->choices[ $key ];
2174 $match = RGFormsModel::choice_value_match( $field, $choice,
$value );
2176 $field->choices[ $key ][
'isSelected'] =
true;
2184 if( floatval(
$field_id ) === floatval( $field->id ) ) {
2186 if(
'list' === $field->type ) {
2189 $list_field_value = array();
2190 foreach ( (array) $list_rows as $row ) {
2191 foreach ( (array) $row as $column ) {
2192 $list_field_value[] = $column;
2196 $field->defaultValue = serialize( $list_field_value );
2225 $the_form = GFAPI::get_form(
$form[
'id'] );
2226 $editable_ids = array();
2228 $editable_ids[] = $field[
'id'];
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 ) ) {
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'] ];
2244 $value = gform_get_meta( $this->entry[
'id'], $rule[
'fieldId'] );
2247 $match = GFFormsModel::matches_operation(
$value, $rule[
'value'], $rule[
'operator'] );
2250 $remove_conditions_rule[] = array( $field[
'id'],
$i );
2257 if ( $remove_conditions_rule ) {
2258 foreach (
$form[
'fields'] as &$field ) {
2259 foreach ( $remove_conditions_rule as $_remove_conditions_r ) {
2261 list( $rule_field_id, $rule_i ) = $_remove_conditions_r;
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'] ) );
2272 $form[
'fields'] = array_values(
$form[
'fields'] );
2280 $use_conditional_logic = apply_filters(
'gravityview/edit_entry/conditional_logic',
true,
$form );
2282 if( $use_conditional_logic ) {
2286 foreach(
$form[
'fields'] as &$field ) {
2288 $field->conditionalLogic = null;
2291 unset(
$form[
'button'][
'conditionalLogic'] );
2309 return $has_conditional_logic;
2313 return apply_filters(
'gravityview/edit_entry/conditional_logic', $has_conditional_logic,
$form );
2340 if( !empty( $_POST[
'lid'] ) && !empty( $_GET[
'entry'] ) && ( $_POST[
'lid'] !== $_GET[
'entry'] ) ) {
2346 if( !empty( $_GET[
'entry'] ) && (
string)$this->entry[
'id'] !== $_GET[
'entry'] ) {
2359 $error = __(
'The link to edit this entry is not valid; it may have expired.',
'gk-gravityview');
2365 $error = __(
'You do not have permission to edit this entry.',
'gk-gravityview');
2368 if( $this->entry[
'status'] ===
'trash' ) {
2369 $error = __(
'You cannot edit the entry; it is in the trash.',
'gk-gravityview' );
2373 if( empty( $error ) ) {
2377 if( $echo && $error !==
true ) {
2379 $error = esc_html( $error );
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;" ) );
2391 gravityview()->log->error(
'{error}', array(
'error' => $error ) );
2409 $error = __(
'You do not have permission to edit this field.',
'gk-gravityview');
2413 if( empty( $error ) ) {
2421 gravityview()->log->error(
'{error}', array(
'error' => $error ) );
2439 if(
GVCommon::has_cap( array(
'gravityforms_edit_entries',
'gravityview_edit_others_entries' ) ) ) {
2443 $field_cap = isset(
$field[
'allow_edit_cap'] ) ?
$field[
'allow_edit_cap'] :
false;
2461 $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field );
2470 $valid = wp_verify_nonce( $_GET[
'edit'], self::$nonce_key );
2479 $valid = apply_filters(
'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field );
2491 if ( empty (
$field->storageType ) ||
$field->storageType !=
'json' ) {
2497 if ( $maybe_json ) {
2498 return implode(
',', $maybe_json );
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' ) ),
2528 $labels = apply_filters(
'gravityview/edit_entry/button_labels', $labels, $this->form, $this->entry, $this->view_id );
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 ...
static getInstance( $passed_post=NULL)
edit_entry_form()
Display the Edit Entry form.
static getInstance( $passed_post=NULL)
fill_post_template( $template, $form, $entry, $do_shortcode=false)
Convert a field content template into prepared output.
$gravityview_view
array $entry array $form array $field_settings
if(! function_exists( 'gravityview_sanitize_html_class')) gravityview_strip_whitespace( $string)
Replace multiple newlines, tabs, and spaces with a single space.
if(! isset( $gravityview)||empty( $gravityview->template)) $template
The entry loop for the list output.
update_calculation_fields()
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?
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.
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.
If this file is called directly, abort.
form_prepare_for_save()
Set visibility to visible and convert field input key to string.
maybe_print_message()
Display success or error message if the form has been submitted.
static directory_link( $post_id=NULL, $add_query_args=true, $context=null)
Generate a URL to the Directory context.
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()
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.
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...
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.
__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.
merge_field_properties( $field, $field_setting)
Override GF Form field properties with the ones defined on the View.
prevent_maybe_process_form()
Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms backend form...
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'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 $supports_save_and_continue
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...
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...
gv_empty( $value, $zero_is_empty=true, $allow_string_booleans=true)
Is the value empty?
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's post object...
user_can_edit_entry( $echo=false)
Check if the user can edit the entry.
if(false !==strpos( $value, '00:00')) $field_id
string $field_id ID of the field being displayed
get_action_labels()
Returns labels for the action links on Edit Entry.
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't be visible based on the Gravity Forms adminOnly field property...
prevent_render_form()
Don't show any forms embedded on a page when GravityView is in Edit Entry mode.
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...