| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; |
| 4 |
} |
| 5 |
?> |
| 6 |
<ul class="form-field-list css_units"> |
| 7 |
|
| 8 |
<?php |
| 9 |
|
| 10 |
$group_key = ''; |
| 11 |
|
| 12 |
$unit_cats = array( |
| 13 |
'all_units' => array( |
| 14 |
'label' => __('All length units', 'microthemer'), |
| 15 |
'items' => array( |
| 16 |
'load_css_unit_sets' => array( |
| 17 |
'is_text' => 1, |
| 18 |
'one_line' => 1, |
| 19 |
'empty_after' => 1, |
| 20 |
'input_id' => 'css_unit_set', |
| 21 |
'combobox' => 'css_length_units', |
| 22 |
'label' => __('Set ALL length units to:', 'microthemer'), |
| 23 |
'explain' => __('Pixels are easier for beginners. But many consider it best practice to rem units for length properties', 'microthemer') |
| 24 |
) |
| 25 |
) |
| 26 |
) |
| 27 |
); |
| 28 |
|
| 29 |
// output CSS unit options |
| 30 |
foreach($this->preferences['my_props'] as $prop_group => $array){ |
| 31 |
|
| 32 |
// skip if non-valid or we've removed a property group |
| 33 |
if ($prop_group == 'sug_values' || empty($this->propertyoptions[$prop_group])) continue; |
| 34 |
|
| 35 |
// loop through default unit props |
| 36 |
if (!empty($this->preferences['my_props'][$prop_group]['pg_props'])){ |
| 37 |
$first = true; |
| 38 |
foreach ($this->preferences['my_props'][$prop_group]['pg_props'] as $prop => $arr){ |
| 39 |
|
| 40 |
if (!isset($this->propertyoptions[$prop_group][$prop]['default_unit'])){ |
| 41 |
continue; |
| 42 |
} |
| 43 |
|
| 44 |
unset($units); |
| 45 |
// user doesn't need to set all padding (for instance) individually |
| 46 |
$factoryUnit = $this->propertyoptions[$prop_group][$prop]['default_unit']; |
| 47 |
$box_model_rel = false; |
| 48 |
$first_in_group = false; |
| 49 |
//$label = $arr['label']; |
| 50 |
$label = $this->propertyoptions[$prop_group][$prop]['label']; |
| 51 |
|
| 52 |
if (!empty($this->propertyoptions[$prop_group][$prop]['unit_rel'])){ |
| 53 |
$box_model_rel = $this->propertyoptions[$prop_group][$prop]['unit_rel']; |
| 54 |
} elseif (!empty($this->propertyoptions[$prop_group][$prop]['rel'])){ |
| 55 |
$box_model_rel = $this->propertyoptions[$prop_group][$prop]['rel']; |
| 56 |
} |
| 57 |
|
| 58 |
if (!empty($this->propertyoptions[$prop_group][$prop]['unit_sub_label'])){ |
| 59 |
$first_in_group = $this->propertyoptions[$prop_group][$prop]['unit_sub_label']; |
| 60 |
} elseif (!empty($this->propertyoptions[$prop_group][$prop]['sub_label'])){ |
| 61 |
$first_in_group = $this->propertyoptions[$prop_group][$prop]['sub_label']; |
| 62 |
} |
| 63 |
|
| 64 |
// only output length units |
| 65 |
if ( !isset($arr['default_unit']) |
| 66 |
or $this->is_non_length_unit($factoryUnit, $prop) |
| 67 |
or ($box_model_rel and !$first_in_group) |
| 68 |
){ |
| 69 |
continue; |
| 70 |
} |
| 71 |
// use group sub label if first box model e.g. padding, margin, border width, border radius |
| 72 |
if ($box_model_rel and $first_in_group){ |
| 73 |
$label = $first_in_group; // . esc_html__(' (all)', 'microthemer'); |
| 74 |
} |
| 75 |
// we don't need position repeated all the time (but no biggy if non-english) |
| 76 |
$label = str_replace(' (Position)', '', $label); |
| 77 |
|
| 78 |
// output pg group heading if new group |
| 79 |
if ($first){ |
| 80 |
// get the label for the property group (can't necessarily rely on $first_in_group) |
| 81 |
foreach ($this->propertyoptions[$prop_group] as $p => $arr){ |
| 82 |
$pg_label = !empty($arr['pg_label']) ? $arr['pg_label'] : ''; |
| 83 |
break; // only need first |
| 84 |
} |
| 85 |
|
| 86 |
$group_key = strtolower(str_replace(' ', '', $pg_label)); |
| 87 |
$unit_cats[$group_key] = array( |
| 88 |
'label' => $pg_label, |
| 89 |
'items' => array() |
| 90 |
); |
| 91 |
|
| 92 |
$first = false; |
| 93 |
} |
| 94 |
|
| 95 |
$unit_cats[$group_key]['items']['cssu_'.$prop] = array( |
| 96 |
'is_text' => 1, |
| 97 |
'one_line' => 1, |
| 98 |
'prop' => $prop, |
| 99 |
'input_class' => 'custom_css_unit', |
| 100 |
'arrow_class' => 'custom_css_unit', |
| 101 |
'combobox' => 'css_length_units', |
| 102 |
'input_name' => 'tvr_preferences[new_css_units]['.$prop_group.']['.$prop.']', |
| 103 |
'input_value' => $this->preferences['my_props'][$prop_group]['pg_props'][$prop]['default_unit'], |
| 104 |
'label' => $label, |
| 105 |
'explain' => __('Set the default CSS unit for ', 'microthemer') . $label |
| 106 |
); |
| 107 |
|
| 108 |
|
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
// output |
| 114 |
echo $this->preferences_grid($unit_cats, 'css-units-grid'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- generated UI markup, values escaped in builder |
| 115 |
?> |
| 116 |
</ul> |
| 117 |
|
| 118 |
|