/** * Columns * * @since 2.2.0 */ function themeblvd_sanitize_columns($input) { $width_options = themeblvd_column_widths(); $output = array(); // Verify number of columns is an integer if (is_numeric($input['num'])) { $output['num'] = $input['num']; } else { $output['num'] = null; } // Verify widths foreach ($input['width'] as $key => $width) { $valid = false; foreach ($width_options[$key . '-col'] as $width_option) { if ($width == $width_option['value']) { $valid = true; } } if ($valid) { $output['width'][$key] = $width; } else { $output['width'][$key] = null; } } return $output; }
/** * Generates option for configuring columns. * * This has been moved to a separate function * because it's a custom addition to the optionframework * module and it's pretty lengthy. * * @since 2.0.0 * * @param $type string type of use, standard or element * @param $id string unique ID for option * @param $name string prefix for form name value * @param $val array currently saved data if exists * @return $output string HTML for option */ function themeblvd_columns_option($type, $id, $name, $val) { /*------------------------------------------------------*/ /* Setup Internal Options /*------------------------------------------------------*/ // Dropdown for number of columns selection $data_num = array(array('name' => __('Hide Columns', 'themeblvd'), 'value' => 0), array('name' => '1 ' . __('Column', 'themeblvd'), 'value' => 1), array('name' => '2 ' . __('Columns', 'themeblvd'), 'value' => 2), array('name' => '3 ' . __('Columns', 'themeblvd'), 'value' => 3), array('name' => '4 ' . __('Columns', 'themeblvd'), 'value' => 4), array('name' => '5 ' . __('Columns', 'themeblvd'), 'value' => 5)); // Dropdowns for column width configuration $data_widths = themeblvd_column_widths(); /*------------------------------------------------------*/ /* Construct <select> Menus /*------------------------------------------------------*/ // Number of columns if ($type == 'element') { unset($data_num[0]); } // Select number of columns $select_number = '<div class="tb-fancy-select">'; $select_number .= '<select class="column-num" name="' . esc_attr($name . '[' . $id . '][num]') . '">'; $current_value = ''; if (!empty($val) && !empty($val['num'])) { $current_value = $val['num']; } foreach ($data_num as $num) { $select_number .= '<option value="' . $num['value'] . '" ' . selected($current_value, $num['value'], false) . '>' . $num['name'] . '</option>'; } $select_number .= '</select>'; $select_number .= '<span class="trigger"></span>'; $select_number .= '<span class="textbox"></span>'; $select_number .= '</div><!-- .tb-fancy-select (end) -->'; // Select column widths $i = 1; $select_widths = '<div class="column-width column-width-0"><p class="inactive">' . __('Columns will be hidden.', 'themeblvd') . '</p></div>'; foreach ($data_widths as $widths) { $select_widths .= '<div class="tb-fancy-select column-width column-width-' . $i . '">'; $select_widths .= '<select name= "' . esc_attr($name . '[' . $id . '][width][' . $i . ']') . '">'; $current_value = ''; if (!empty($val) && !empty($val['width'][$i])) { $current_value = $val['width'][$i]; } foreach ($widths as $width) { $select_widths .= '<option value="' . $width['value'] . '" ' . selected($current_value, $width['value'], false) . '>' . $width['name'] . '</option>'; } $select_widths .= '</select>'; $select_widths .= '<span class="trigger"></span>'; $select_widths .= '<span class="textbox"></span>'; $select_widths .= '</div><!-- .tb-fancy-select (end) -->'; $i++; } /*------------------------------------------------------*/ /* Primary Output /*------------------------------------------------------*/ $output = sprintf('<div class="select-wrap alignleft">%s</div>', $select_number); $output .= sprintf('<div class="select-wrap alignleft">%s</div>', $select_widths); $output .= '<div class="clear"></div>'; return $output; }