diff --git a/fields/class-livy-acf-field-zelda-v5.php b/fields/class-livy-acf-field-zelda-v5.php
index d3cd185..4e56805 100644
--- a/fields/class-livy-acf-field-zelda-v5.php
+++ b/fields/class-livy-acf-field-zelda-v5.php
@@ -227,6 +227,11 @@ function render_field( $field ) {
* Review the data of $field.
* This will show what data is available
*/
+ $stored = $field['value'] ?? null;
+ $stored_type = $stored['type'] ?? false;
+ $stored_value = $stored['value'] ?? false;
+ $stored_class = $stored['class'] ?? false;
+ $stored_text = $stored['text'] ?? false;
/**
* Generate a list of possible link types.
@@ -265,13 +270,6 @@ function render_field( $field ) {
$type_options['external'] = "External";
}
-// echo '
';
-// var_dump( $field );
-//
-//
-// var_dump( $type_options );
-// echo ' ';
-
/**
* Generate some input fields.
*/
@@ -288,13 +286,13 @@ function render_field( $field ) {
printf(
'%s ',
$label['label'],
- join( '', Arrays::mapKeys( function ( $value, $key ) use ( $field, $label ) {
+ join( '', Arrays::mapKeys( function ( $value, $key ) use ( $stored_type, $label ) {
return [
sprintf(
'%s ',
$label['slug'],
$key,
- $label['slug'] . '/' . $key == $field['value']['type'] ? 'selected' : null,
+ $label['slug'] . '/' . $key == $stored_type ? 'selected' : null,
$value
)
];
@@ -304,7 +302,7 @@ function render_field( $field ) {
printf(
'%s ',
$option,
- $option == $field['value']['type'] ? 'selected' : null,
+ $option == $stored_type ? 'selected' : null,
$label
);
}
@@ -330,7 +328,7 @@ function render_field( $field ) {
printf(
'Archive ',
$key . '_archive',
- $field['value']['content'][ $key ] == $key . '_archive' ? 'selected' : null
+ $stored_value == $key . '_archive' ? 'selected' : null
);
} ?>
@@ -343,7 +341,7 @@ function render_field( $field ) {
foreach ( $this_type as $post ) {
printf( '%s ',
$post->ID,
- (int) $field['value']['content'][ $key ] == $post->ID ? 'selected' : null,
+ intval( $stored_value ) == $post->ID ? 'selected' : null,
$post->post_title
);
}
@@ -367,6 +365,7 @@ function render_field( $field ) {
+
$key ) );
if ( $this_taxonomy && count( $this_taxonomy ) > 0
) {
@@ -374,7 +373,7 @@ function render_field( $field ) {
/** @var $taxonomy \WP_Term */
printf( '%s ',
$taxonomy->term_taxonomy_id,
- (int) $field['value']['taxonomy'][ $key ] == $taxonomy->term_taxonomy_id ? 'selected' : null,
+ intval( $stored_value ) == $taxonomy->term_taxonomy_id ? 'selected' : null,
$taxonomy->name
);
}
@@ -394,7 +393,7 @@ function render_field( $field ) {
+ value=""/>
[external]">
+ value=""/>
Class
+ value="">
Text
+ value="">
get_type_value_from_form( $value['type'], $value );
- return $value;
-
+ return array(
+ 'type' => $value['type'],
+ 'value' => $destination,
+ 'class' => $value['user_class'] ?? false,
+ 'text' => $value['user_text'] ?? false,
+ );
}
@@ -681,7 +705,7 @@ function format_value( $value, $post_id, $field ) {
$type = explode( '/', $value['type'] );
- $destination_raw = Arrays::pluck( $value, $type );
+ $destination_raw = $value['value'];
$destination = false;
switch ( $type[0] ) {
case 'content' :
@@ -707,8 +731,8 @@ function format_value( $value, $post_id, $field ) {
if ( $destination ) {
- $class = trim( $value['user_class']
- ? esc_attr( $field['link_class'] . ' ' . $value['user_class'] )
+ $class = trim( $value['class']
+ ? esc_attr( $field['link_class'] . ' ' . $value['class'] )
: esc_attr( $field['link_class'] ) );
$target = $field['new_tab']
@@ -720,7 +744,7 @@ function format_value( $value, $post_id, $field ) {
esc_attr( $destination ),
esc_attr( $class ),
$target,
- $value['user_text']
+ $value['text']
);
}
@@ -795,6 +819,18 @@ function validate_value( $valid, $value, $field, $input ) {
return false;
};
+ if ( ! empty( $value['user_class'] ) ) {
+ if ( 1 !== preg_match( '/^[a-zA-Z_\-0-9 ]*$/m', $value['user_class'] ) ) {
+ return __( 'Enter valid class names.', 'acf-zelda' );
+ }
+ }
+
+ if ( ! empty( $value['user_text'] ) ) {
+ if ( wp_kses_post( $value['user_text'] ) !== $value['user_text'] ) {
+ return __( 'Enter valid link text.', 'acf-zelda' );
+ }
+ }
+
$type = explode( '/', $value['type'] );
$destination = Arrays::pluck( $value, $type );