ID, $field['id'], true );
// Get data to display in field
if ( isset( $option ) ) {
$data = $option;
}
} else {
// Get saved option
$option_name .= $field['id'];
$option = get_option( $option_name );
// Get data to display in field
if ( isset( $option ) ) {
$data = $option;
}
}
// Show default data if no option saved and default is supplied
if ( $data === false && isset( $field['default'] ) ) {
$data = $field['default'];
} elseif ( $data === false ) {
$data = '';
}
$html = '';
switch( $field['type'] ) {
case 'text':
case 'url':
case 'email':
$html .= '' . "\n";
break;
case 'password':
case 'number':
case 'hidden':
$min = '';
if ( isset( $field['min'] ) ) {
$min = ' min="' . esc_attr( $field['min'] ) . '"';
}
$max = '';
if ( isset( $field['max'] ) ) {
$max = ' max="' . esc_attr( $field['max'] ) . '"';
}
$html .= '' . "\n";
break;
case 'text_secret':
$html .= '' . "\n";
break;
case 'textarea':
$html .= '
'. "\n";
break;
case 'checkbox':
$checked = '';
if ( $data && 'on' == $data ) {
$checked = 'checked="checked"';
}
$html .= '' . "\n";
break;
case 'checkbox_multi':
foreach ( $field['options'] as $k => $v ) {
$checked = false;
if ( in_array( $k, $data ) ) {
$checked = true;
}
$html .= ' ';
}
break;
case 'radio':
foreach ( $field['options'] as $k => $v ) {
$checked = false;
if ( $k == $data ) {
$checked = true;
}
$html .= ' ';
}
break;
case 'select':
$html .= ' ';
break;
case 'select_multi':
$html .= ' ';
break;
case 'image':
$image_thumb = '';
if ( $data ) {
$image_thumb = wp_get_attachment_thumb_url( $data );
}
$html .= '
' . "\n";
$html .= '' . "\n";
$html .= '' . "\n";
$html .= '
' . "\n";
break;
case 'color':
?>
' . $this->display_field( $field, $post, false ) . '
' . "\n"; echo $field; } /** * Save metabox fields * @param integer $post_id Post ID * @return void */ public function save_meta_boxes ( $post_id = 0 ) { if ( ! $post_id ) return; $post_type = get_post_type( $post_id ); $fields = apply_filters( $post_type . '_custom_fields', array(), $post_type ); if ( ! is_array( $fields ) || 0 == count( $fields ) ) return; foreach ( $fields as $field ) { if ( isset( $_REQUEST[ $field['id'] ] ) ) { update_post_meta( $post_id, $field['id'], $this->validate_field( $_REQUEST[ $field['id'] ], $field['type'] ) ); } else { update_post_meta( $post_id, $field['id'], '' ); } } } }