/** * Format an option array into HTML * * * @access public * * @param unknown $setting * * @return string HTML. */ public function settings_options_format($setting) { if (empty($setting)) { return false; } $defaults = apply_filters($this->id . '_options_defaults', array('name' => '', 'desc' => '', 'placeholder' => '', 'class' => '', 'tip' => '', 'id' => '', 'css' => '', 'type' => 'text', 'std' => '', 'select2' => false, 'multiple' => false, 'options' => array(), 'restrict' => array(), 'settings' => array())); // Each to it's own variable for slim-ness' sakes. $setting = shortcode_atts($defaults, $setting); $restrict_defaults = array('min' => 0, 'max' => '', 'step' => 'any'); $setting['restrict'] = shortcode_atts($restrict_defaults, $setting['restrict']); $setting['value'] = $this->get_option($setting['id']); $setting['value'] = $setting['value'] !== false ? maybe_unserialize($setting['value']) : false; $setting['value'] = SF_Format_Options::sanitize_value($setting['value'], $setting); $setting['title'] = $setting['name']; $setting['name'] = $this->id . "_options[{$setting['id']}]"; $setting['grouped'] = !$setting['title'] ? ' style="padding-top:0px;"' : ''; $setting['tip'] = SF_Format_Options::get_formatted_tip($setting['tip']); $header_types = apply_filters($this->id . '_options_header_types', array('heading', 'title')); extract($setting); $description = $desc && !$grouped && $type != 'checkbox' ? '<br /><small>' . $desc . '</small>' : '<label for="' . $id . '"> ' . $desc . '</label>'; $description = (in_array($type, $header_types) || $type == 'radio') && !empty($desc) ? '<p>' . $desc . '</p>' : $description; ?> <?php if (!in_array($type, $header_types)) { ?> <!-- Header of the option. --> <tr valign="top"> <th scope="row"<?php echo $grouped; ?> > <?php echo $tip; ?> <?php if (!$grouped) { ?> <label for="<?php echo $name; ?> " class="description"><?php echo $title; ?> </label> <?php } ?> </th> <td <?php echo $grouped; ?> > <?php } ?> <?php foreach ($header_types as $header) { if ($type != $header) { continue; } ?> <tr> <th scope="col" colspan="2"> <h3 class="title"><?php echo $title; ?> </h3> <?php echo $description; ?> </th> </tr> <?php } ?> <?php switch ($type) { case 'text': case 'color': case 'number': if ($type == 'color') { $type = 'text'; $class .= ' colorpick'; $description .= '<div id="colorPickerDiv_' . $id . '" class="colorpickdiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"></div>'; } ?> <input name="<?php echo $name; ?> " id="<?php echo $id; ?> " type="<?php echo $type; ?> " <?php if ($type == 'number') { ?> min="<?php echo $restrict['min']; ?> " max="<?php echo $restrict['max']; ?> " step="<?php echo $restrict['step']; ?> " <?php } ?> class="regular-text <?php echo $class; ?> " style="<?php echo $css; ?> " placeholder="<?php echo $placeholder; ?> " value="<?php echo $value !== false ? $value : $std; ?> " /> <?php echo $description; break; case 'checkbox': $selected = $value !== false ? $value : $std; if ($multiple) { foreach ($options as $key => $desc) { ?> <input name="<?php echo $name; echo $multiple ? '[]' : ''; ?> " id="<?php echo $id . '_' . $key; ?> " type="checkbox" class="<?php echo $class; ?> " style="<?php echo $css; ?> " value="<?php echo $key; ?> " <?php self::checked($value, $key); ?> /> <label for="<?php echo $id . '_' . $key; ?> "> <?php echo $desc; ?> </label> <br/> <?php } } else { ?> <input name="<?php echo $name; ?> " id="<?php echo $id; ?> " type="checkbox" class="<?php echo $class; ?> " style="<?php echo $css; ?> " <?php checked($selected, 1); ?> /> <?php echo $description; } break; case 'radio': $selected = $value !== false ? $value : $std; foreach ($options as $key => $val) { ?> <label class="radio"> <input type="radio" name="<?php echo $name; ?> " id="<?php echo $key; ?> " value="<?php echo $key; ?> " class="<?php echo $class; ?> " <?php checked($selected, $key); ?> /> <?php echo $val; ?> </label><br/> <?php } echo $description; break; case 'single_select_page': $selected = $value !== false ? $value : $std; $args = array('name' => $name, 'id' => $id, 'sort_order' => 'ASC', 'echo' => 0, 'selected' => $selected); echo str_replace("'>", "'><option></option>", wp_dropdown_pages($args)); echo $description; if ($select2) { ?> <script type="text/javascript">jQuery(function () { jQuery("#<?php echo $id; ?> ").select2({ allowClear: true, placeholder: "<?php _e('Select a page...', 'geczy'); ?> ", width: '350px' }); });</script> <?php } break; case 'select': $selected = $value !== false ? $value : $std; $options = apply_filters($this->id . '_select_options', $options, $setting); ?> <select id="<?php echo $id; ?> " class="<?php echo $class; ?> " style="<?php echo $css; ?> " name="<?php echo $name; echo $multiple ? '[]' : ''; ?> " <?php echo $multiple ? 'multiple="multiple"' : ''; ?> > <?php foreach ($options as $key => $val) { ?> <option value="<?php echo $key; ?> " <?php self::selected($selected, $key); ?> ><?php echo $val; ?> </option> <?php } ?> </select> <?php echo $description; if ($select2) { ?> <script type="text/javascript">jQuery(function () { jQuery("#<?php echo $id; ?> ").select2({ width: '350px' }); });</script> <?php } break; case 'textarea': ?> <textarea name="<?php echo $name; ?> " id="<?php echo $id; ?> " class="large-text <?php echo $class; ?> " style="<?php if ($css) { echo $css; } else { echo 'width:300px;'; } ?> " placeholder="<?php echo $placeholder; ?> " rows="3" ><?php echo $value !== false ? $value : $std; ?> </textarea> <?php echo $description; break; case 'wysiwyg': wp_editor($value, $id, array('textarea_name' => $name)); echo $description; break; default: do_action($this->id . '_options_type_' . $type, $setting); break; } /* Footer of the option. */ if (!in_array($type, $header_types)) { echo '</td></tr>'; } }