• Resolved youngmicroserf

    (@youngmicroserf)


    Hey,

    love the plugin. One thing I’m missing the ability to group values under a subheader, and another one is the ability to have a combination of “amount” and “unit” (say: 10 (input) px (select)) in the same line for the the same item, which is very useful for allowing CSS modifications like border width and the like.

    I may try to extend the plugin myself, but I thought I’d mention this here as well.

    Thanks again!

    https://www.ads-software.com/extend/plugins/option-tree/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter youngmicroserf

    (@youngmicroserf)

    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
          	}
    Plugin Author Derek Herman

    (@valendesigns)

    Looks promising, I’ll look over the code now and include it in the new update today if everything is working correctly. Thanks for your contribution.

    Plugin Author Derek Herman

    (@valendesigns)

    It’s been added and the code was updated slightly. I’ll push it to the live server later today with the other updates.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: OptionTree] Feature request – subheader / value/unit-selector’ is closed to new replies.