Hey, if anyone is interested, I made a couple of changes to the code to get a value-unit datatype – that is turning a value-unit pair into an array when being saved into the options table and adding a form element to display and change the value-unit pair. Maybe there’s a better way to do it, but it works for me…
a) new form element ‘valueunit’ as new file ‘valueunit.php’ in [plugin_root]/functions/admin/
This file is displaying a simple combined element of input and select box. The two elements are then saved as variables with the valueunit-key and the respective suffix “_value” and “_unit”.
<?php if (!defined('OT_VERSION')) exit('No direct script access allowed');
/**
* Input Option
*
**/
function option_tree_valueunit( $value, $settings, $int )
{
?>
<div class="option option-valueunit">
<h3><?php echo htmlspecialchars_decode( $value->item_title ); ?></h3>
<div class="section">
<div class="element">
<input type="text" name="<?php echo $value->item_id; ?>_value" id="<?php echo $value->item_id; ?>_value" value="<?php if ( isset($settings[$value->item_id]) ) { echo htmlspecialchars( stripslashes( $settings[$value->item_id[0]] ), ENT_QUOTES); } ?>" />
<div class="select_wrapper">
<select name="<?php echo $value->item_id; ?>_unit" class="select unit">
<?php
echo '<option value="">-- Choose One --</option>';
$units = array(
'px' => 'px',
'%' => '%',
'em' => 'em',
'pt' => 'pt'
);
foreach ( $units as $unit )
{
$selected = '';
if ( $settings[$value->item_id[1]] == trim( $unit ) )
{ $selected = ' selected="selected"'; }
echo '<option'.$selected.'>'.trim( $unit ).'</option>';
}
?>
</select>
</div>
</div>
<div class="description">
<?php echo htmlspecialchars_decode( $value->item_desc ); ?>
</div>
</div>
</div>
<?php
}
b) changes made to [plugin_root]/functions/functions_load.php ->
include the new form part. This is to load the new form part in the options panel.
include( 'admin/valueunit.php' );
at the appropriate position.
c) changes made to [plugin_root]/admin/settings.php ->
display the new option-type in the select box in the settings form.
Added a new array element in the types-array after ca. line 113.
'valueunit' => 'ValueUnit',
d) changes made to [plugin_root]/classes/class.admin.php -> function option_tree_array_save. Added an else-if condition checking for the new option type “valueunit” and then taking the value-unit pair sent and write it into an array using the single original key after ca. line 491.
else if ($value->item_type == "valueunit" ) {
$key = trim( $value->item_id );
$tempkeys = array('_value', '_unit');
foreach ($tempkeys as $tempkey) {
$value[]=$_REQUEST[$key.$tempkey];
}
$new_settings[$key] = $value
}