name_prefix = $newfix;
}
/**
* return the html for any field based on given params
* Prepopulate the value in parameter $current_value. If no current_value, then $field['value'] will prepopulate.
*/
public function get_field($field, $current_value = '', $enabled = true){
if(gettype($current_value) == 'string'){
$current_value = htmlentities($current_value);
}
/**** Fallback defaults */
if(!isset($field['type'])){
$field['type'] = 'text'; //--strict, and practical
}
if(!isset($field['name'])){
$field['name'] = false; //--strict
}
if(!isset($field['value'])){
$field['value'] = ''; //--strict
}
if(!isset($field['default'])){
$field['default'] = ''; //--strict
}
if(!isset($field['label'])){
$field['label'] = ''; //--strict
}
if(!isset($field['tooltip'])){
$field['tooltip'] = ''; //--strict
}
if(!isset($field['placeholder'])){
$field['placeholder'] = ''; //--strict
}
if(!isset($field['options'])){
$field['options'] = array(); //--strict
}
/**** Prepare auto postid for some fields */
global $post;
if($post && $post->ID){
$post_id = $post->ID;
}else{
$post_id = '';
}
/**** Prepare some shortened parameters. These will most likely be used later */
$prefix = $this->name_prefix;
$type = $field['type'];
$label = $field['label'];
$tooltip = $field['tooltip'];
$placeholder= $field['placeholder'];
$default = $field['default'];
$value = $field['value']; //--strict
$options = $field['options']; //--strict
$checked = ' checked="checked" ';
$selected = ' selected="selected" ';
$current_active = false; //--strict
$image_manipulators = ''; //--strict
//TODO: TYPE MAP
/**** Verify the "name" parameter */
if(!$field['name']){
if($type == 'custom' && !$field['name']){
//If type="custom", then we can just create a fake name. Type custom does not save any values (atleast not automatically!)
$field['name'] = 'fakename-'.mt_rand(1,100000000);
}else{
return 'Error: Field missing parameter "name" for a field of type "'.$type.'"
';
}
}
//Name is OK
$name = $field['name'];
$prefixed_name = $prefix.$name;
$id = $prefixed_name;
/**** Some possible preparations for the previously saved value (if any) */
if($current_value === ''){
/* NO current value */
//Default value as fallback
if($default){
$current_value = $default;
}
}
/**** Prepare attributes */
$attr_id = ' id="'.$id.'"'; //for functioning labels. Also, practical
$attr_type = ' type="'.$type.'"';
$attr_name = ' name="'.$prefixed_name.'"';
$attr_value = ' value="'.$current_value.'"';
/**** Optional and tagtype specifics */
//Labels! Connected to the input id
$element_label = $label
? ''
: '';
//Tooltips. Basic hoverable
$tooltip = $tooltip
? '