Skip to content

Commit

Permalink
admin api updated
Browse files Browse the repository at this point in the history
  • Loading branch information
rafasashi committed Apr 22, 2024
1 parent 0446222 commit d6c6b42
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions includes/lib/class-wordpress-plugin-template-admin-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function display_field( $data = array(), $post = null, $echo = true ) {

// Get saved field data.

$data = get_post_meta( $post->ID, $field['id'], true );
$data = get_post_meta( $post->ID, $option_name, true );
}
else {

Expand All @@ -78,6 +78,18 @@ public function display_field( $data = array(), $post = null, $echo = true ) {
$data = '';
}

// get attributes

$style = ( !empty($field['style']) ? ' style="'.$field['style'].'"' : '' );

$disabled = ( ( isset($field['disabled']) && $field['disabled'] === true ) ? ' disabled="disabled"' : '' );

$required = ( ( isset($field['required']) && $field['required'] === true ) ? ' required="true"' : '' );

$placeholder = ( isset($field['placeholder']) ? esc_attr($field['placeholder']) : '' );

// get html

$html = '';

switch ( $field['type'] ) {
Expand All @@ -86,7 +98,7 @@ public function display_field( $data = array(), $post = null, $echo = true ) {
case 'url':
case 'color':
case 'email':
$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="text" name="' . esc_attr( $option_name ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" value="' . esc_attr( $data ) . '" />' . "\n";
$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="text" name="' . esc_attr( $option_name ) . '" placeholder="' . $placeholder . '" value="' . esc_attr( $data ) . '"' . $style . $required . $disabled . '/>' . "\n";
break;

case 'password':
Expand All @@ -101,15 +113,15 @@ public function display_field( $data = array(), $post = null, $echo = true ) {
if ( isset( $field['max'] ) ) {
$max = ' max="' . esc_attr( $field['max'] ) . '"';
}
$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . esc_attr( $field['type'] ) . '" name="' . esc_attr( $option_name ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" value="' . esc_attr( $data ) . '"' . $min . '' . $max . '/>' . "\n";
$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . esc_attr( $field['type'] ) . '" name="' . esc_attr( $option_name ) . '" placeholder="' . $placeholder . '" value="' . esc_attr( $data ) . '"' . $min . $max . $style . $required . $disabled . '/>' . "\n";
break;

case 'text_secret':
$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="text" name="' . esc_attr( $option_name ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" value="" />' . "\n";
$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="text" name="' . esc_attr( $option_name ) . '" placeholder="' . $placeholder . '" value=""' . $style . $required . $disabled . '/>' . "\n";
break;

case 'textarea':
$html .= '<textarea id="' . esc_attr( $field['id'] ) . '" rows="5" cols="50" name="' . esc_attr( $option_name ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '">' . $data . '</textarea><br/>' . "\n";
$html .= '<textarea id="' . esc_attr( $field['id'] ) . '" rows="5" cols="50" name="' . esc_attr( $option_name ) . '" placeholder="' . $placeholder . '"' . $style . $required . $disabled . '>' . $data . '</textarea><br/>' . "\n";
break;

case 'checkbox':
Expand All @@ -136,13 +148,13 @@ public function display_field( $data = array(), $post = null, $echo = true ) {
if ( $k === $data ) {
$checked = true;
}
$html .= '<label for="' . esc_attr( $field['id'] . '_' . $k ) . '"><input type="radio" ' . checked( $checked, true, false ) . ' name="' . esc_attr( $option_name ) . '" value="' . esc_attr( $k ) . '" id="' . esc_attr( $field['id'] . '_' . $k ) . '" /> ' . $v . '</label> ';
$html .= '<label for="' . esc_attr( $field['id'] . '_' . $k ) . '" style="margin-right:5px;"><input type="radio" ' . checked( $checked, true, false ) . ' name="' . esc_attr( $option_name ) . '" value="' . esc_attr( $k ) . '" id="' . esc_attr( $field['id'] . '_' . $k ) . '" /> ' . $v . '</label> ';
}
break;

case 'select':

$html .= '<select name="' . esc_attr( $option_name ) . '" id="' . esc_attr( $field['id'] ) . '">';
$html .= '<select name="' . esc_attr( $option_name ) . '" id="' . esc_attr( $field['id'] ) . '"' . $style . $required . $disabled . '>';

foreach ( $field['options'] as $k => $v ) {

Expand All @@ -165,7 +177,7 @@ public function display_field( $data = array(), $post = null, $echo = true ) {
break;

case 'select_multi':
$html .= '<select name="' . esc_attr( $option_name ) . '[]" id="' . esc_attr( $field['id'] ) . '" multiple="multiple">';
$html .= '<select name="' . esc_attr( $option_name ) . '[]" id="' . esc_attr( $field['id'] ) . '" multiple="multiple"' . $style . $required . $disabled . '>';
foreach ( $field['options'] as $k => $v ) {
$selected = false;
if ( in_array( $k, (array) $data, true ) ) {
Expand Down

0 comments on commit d6c6b42

Please sign in to comment.