Skip to content

Commit

Permalink
Tweak - Hidden field editable compatibility (#1327)
Browse files Browse the repository at this point in the history
* Tweak - Field which are made hidden are editable

* Tweak - Hidden field also editable

* Fix phpcs

* Fix - PHPCS
  • Loading branch information
NirajChaudhary143 authored Sep 5, 2024
1 parent 56f5b1d commit e52d267
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 12 additions & 1 deletion includes/evf-core-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,8 @@ function evf_html_attributes( $id = '', $class = array(), $datas = array(), $att
$id = trim( $id );
$parts = array();

$is_edit_entry = isset( $_GET['edit-entry'] ) && ! sanitize_text_field( wp_unslash( empty( $_GET['edit-entry'] ) ) ) ? true : false;

if ( ! empty( $id ) ) {
$id = sanitize_html_class( $id );
if ( ! empty( $id ) ) {
Expand All @@ -984,6 +986,10 @@ function evf_html_attributes( $id = '', $class = array(), $datas = array(), $att
if ( ! empty( $class ) ) {
$class = evf_sanitize_classes( $class, true );
if ( ! empty( $class ) ) {
// While editing hidden field should be visible.
if ( $is_edit_entry ) {
$class = str_replace( 'evf-field-hidden', '', $class );
}
$parts[] = 'class="' . $class . '"';
}
}
Expand All @@ -1003,7 +1009,12 @@ function evf_html_attributes( $id = '', $class = array(), $datas = array(), $att
} else {
$escaped_att = sanitize_html_class( $att );
}
$parts[] = $escaped_att . '="' . esc_attr( $val ) . '"';
// While editing, fields must be visible even if they are hidden.
if ( 'style' == $escaped_att && $is_edit_entry ) {
$parts[] = 'style = "display: block"';
} else {
$parts[] = $escaped_att . '="' . esc_attr( $val ) . '"';
}
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion includes/fields/class-evf-field-hidden.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,14 @@ public function field_display( $field, $field_atts, $form_data ) {
// Define data.
$primary = $field['properties']['inputs']['primary'];

// For edit purpose.
$is_edit_entry = isset( $_GET['edit-entry'] ) && sanitize_text_field( wp_unslash( $_GET['edit-entry'] ) ) ? true : false;
$field_type = $is_edit_entry ? 'text' : 'hidden';

// Primary field.
printf(
'<input type="hidden" %s>',
'<input type="%s" %s>',
$field_type,
evf_html_attributes( $primary['id'], $primary['class'], $primary['data'], $primary['attr'] )
);
}
Expand Down

0 comments on commit e52d267

Please sign in to comment.