public function format_option_for_display($item) { $options = FFLCommerce_Base::get_options(); if (!isset($item['id'])) { return ''; } // ensure we have an id to work with $display = ""; // each item builds it's output into this and it's returned for echoing $class = ""; if (isset($item['class'])) { $class = $item['class']; } // display a tooltip if there is one in it's own table data element before the item to display $display .= '<td class="fflcommerce-tooltips">'; if (!empty($item['tip'])) { $display .= '<a href="#" tip="' . esc_attr($item['tip']) . '" class="tips" tabindex="99"></a>'; } $display .= '</td><td class="forminp">'; $disabled = ''; $disabledItems = array(); if (isset($item['extra']) && isset($item['extra']['disabled'])) { if ($item['extra']['disabled'] === true) { $disabled = ' disabled'; } else { if (is_array($item['extra']['disabled'])) { $disabledItems = $item['extra']['disabled']; } } } /* * work off the option type and format output for display for each type */ switch ($item['type']) { case 'user_defined': if (isset($item['display'])) { if (is_callable($item['display'], true)) { $display .= call_user_func($item['display']); } } break; case 'default_gateway': $id = $item['id']; $display .= '<select id="' . $id . '" class="fflcommerce-input fflcommerce-select ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $id . ']"' . $disabled . ' >'; $gateways = fflcommerce_payment_gateways::get_available_payment_gateways(); foreach ($gateways as $slug => $gateway) { $display .= '<option value="' . esc_attr($slug) . '" ' . selected($options->get($id), $slug, false) . disabled(in_array($id, $disabledItems, false)) . ' />' . $gateway->title . '</option>'; } $display .= '</select>'; ?> <script type="text/javascript"> /*<![CDATA[*/ jQuery(function($){ $("#<?php echo $id; ?> ").select2({ width: '250px' }); }); /*]]>*/ </script> <?php break; case 'gateway_options': foreach (fflcommerce_payment_gateways::payment_gateways() as $gateway) { $gateway->admin_options(); } break; case 'shipping_options': foreach (fflcommerce_shipping::get_all_methods() as $shipping_method) { $shipping_method->admin_options(); } break; case 'tax_rates': $display .= $this->format_tax_rates_for_display($item); break; case 'single_select_page': $page_setting = (int) $options->get($item['id']); $args = array('name' => FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']', 'id' => $item['id'], 'sort_order' => 'ASC', 'echo' => 0, 'selected' => $page_setting); if (isset($item['extra'])) { $args = wp_parse_args($item['extra'], $args); } $display .= wp_dropdown_pages($args); $parts = explode('<select', $display); $id = $item['id']; $display = $parts[0] . '<select id="' . $id . '" class="' . $class . '"' . $parts[1]; ?> <script type="text/javascript"> /*<![CDATA[*/ jQuery(function($){ $("#<?php echo $id; ?> ").select2({ width: '250px' }); }); /*]]>*/ </script> <?php break; case 'single_select_country': $country_setting = (string) $options->get($item['id']); $add_empty = false; if (isset($item['options']['add_empty']) && $item['options']['add_empty']) { $add_empty = true; } if (strstr($country_setting, ':')) { $temp = explode(':', $country_setting); $country = current($temp); $state = end($temp); } else { $country = $country_setting; $state = '*'; } $id = $item['id']; $display .= '<select id="' . $id . '" class="single_select_country ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']"' . $disabled . '>'; $display .= fflcommerce_countries::country_dropdown_options($country, $state, true, false, false, $add_empty); $display .= '</select>'; ?> <script type="text/javascript"> /*<![CDATA[*/ jQuery(function($){ $("#<?php echo $id; ?> ").select2({ width: '500px' }); }); /*]]>*/ </script> <?php break; case 'multi_select_countries': $countries = fflcommerce_countries::get_countries(); $selections = (array) $options->get($item['id']); $display .= '<select multiple="multiple" id="' . $item['id'] . '" class="fflcommerce-input fflcommerce-select ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . '][]"' . $disabled . '>'; foreach ($countries as $key => $val) { $display .= '<option value="' . esc_attr($key) . '" ' . selected(in_array($key, $selections), true, false) . disabled(in_array($key, $disabledItems, false)) . ' />' . $val . '</option>'; } $display .= '</select>'; $id = $item['id']; ?> <script type="text/javascript"> /*<![CDATA[*/ jQuery(function($){ $("#<?php echo $id; ?> ").select2({ width: '500px' }); }); /*]]>*/ </script> <?php break; case 'button': if (isset($item['extra'])) { $display .= '<a id="' . $item['id'] . '" class="button ' . $class . '" href="' . esc_attr($item['extra']) . '">' . esc_attr($item['desc']) . '</a>'; } $item['desc'] = ''; // temporarily remove it so it doesn't display twice break; case 'decimal': // decimal numbers are positive or negative 0-9 inclusive, may include decimal $display .= '<input id="' . $item['id'] . '" class="fflcommerce-input fflcommerce-text ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']" type="number" step="any" size="20" value="' . esc_attr($options->get($item['id'])) . '"' . $disabled . ' />'; break; case 'integer': // integer numbers are positive or negative 0-9 inclusive // integer numbers are positive or negative 0-9 inclusive case 'natural': // natural numbers are positive 0-9 inclusive $display .= '<input id="' . $item['id'] . '" class="fflcommerce-input fflcommerce-text ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']" type="number" size="20" value="' . esc_attr($options->get($item['id'])) . '"' . $disabled . ' />'; break; case 'text': // any character sequence $display .= '<input id="' . $item['id'] . '" class="fflcommerce-input fflcommerce-text ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']" type="text" size="20" value="' . esc_attr($options->get($item['id'])) . '"' . $disabled . ' />'; break; case 'midtext': $display .= '<input id="' . $item['id'] . '" class="fflcommerce-input fflcommerce-text ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']" type="text" size="40" value="' . esc_attr($options->get($item['id'])) . '"' . $disabled . ' />'; break; case 'longtext': $display .= '<input id="' . $item['id'] . '" class="fflcommerce-input fflcommerce-text ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']" type="text" size="80" value="' . esc_attr($options->get($item['id'])) . '"' . $disabled . ' />'; break; case 'email': $display .= '<input id="' . $item['id'] . '" class="fflcommerce-input fflcommerce-text fflcommerce-email ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']" type="text" size="40" value="' . esc_attr($options->get($item['id'])) . '"' . $disabled . ' />'; break; case 'codeblock': case 'textarea': $cols = '60'; if (isset($item['choices'])) { $ta_options = $item['choices']; if (isset($ta_options['cols'])) { $cols = $ta_options['cols']; } } $ta_value = stripslashes($options->get($item['id'])); $display .= '<textarea id="' . $item['id'] . '" class="fflcommerce-input fflcommerce-textarea ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']" cols="' . $cols . '" rows="4"' . $disabled . '>' . esc_textarea($ta_value) . '</textarea>'; break; case "radio": // default to horizontal display of choices ( 'horizontal' may or may not be defined ) if (!isset($item['extra']) || !in_array('vertical', $item['extra'])) { $display .= '<div class="fflcommerce-radio-horz">'; foreach ($item['choices'] as $option => $name) { $display .= '<input class="fflcommerce-input fflcommerce-radio ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']" id="' . $item['id'] . '[' . $option . ']" type="radio" value="' . $option . '" ' . checked($options->get($item['id']), $option, false) . disabled(in_array($option, $disabledItems), true, false) . ' /><label for="' . $item['id'] . '[' . $option . ']">' . $name . '</label>'; } $display .= '</div>'; } else { if (isset($item['extra']) && in_array('vertical', $item['extra'])) { $display .= '<ul class="fflcommerce-radio-vert">'; foreach ($item['choices'] as $option => $name) { $display .= '<li><input class="fflcommerce-input fflcommerce-radio ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']" id="' . $item['id'] . '[' . $option . ']" type="radio" value="' . $option . '" ' . checked($options->get($item['id']), $option, false) . disabled(in_array($option, $disabledItems), true, false) . ' /><label for="' . $item['id'] . '[' . $option . ']">' . $name . '</label></li>'; } $display .= '</ul>'; } } break; case 'checkbox': $display .= '<span class="fflcommerce-container"><input id="' . $item['id'] . '" type="checkbox" class="fflcommerce-input fflcommerce-checkbox ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']" ' . checked($options->get($item['id']), 'yes', false) . $disabled . ' /><label for="' . $item['id'] . '">' . $item['name'] . '</label></span>'; break; case 'multicheck': $multi_stored = $options->get($item['id']); // default to horizontal display of choices ( 'horizontal' may or may not be defined ) if (!isset($item['extra']) || !in_array('vertical', $item['extra'])) { $display .= '<div class="fflcommerce-multi-checkbox-horz ' . $class . '">'; foreach ($item['choices'] as $key => $option) { $display .= '<input id="' . $item['id'] . '_' . $key . '" class="fflcommerce-input" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . '][' . $key . ']" type="checkbox" ' . checked($multi_stored[$key], true, false) . disabled(in_array($key, $disabledItems, false)) . ' /> <label for="' . $item['id'] . '_' . $key . '">' . $option . '</label>'; } $display .= '</div>'; } else { if (isset($item['extra']) && in_array('vertical', $item['extra'])) { $display .= '<ul class="fflcommerce-multi-checkbox-vert ' . $class . '">'; foreach ($item['choices'] as $key => $option) { $display .= '<li><input id="' . $item['id'] . '_' . $key . '" class="fflcommerce-input" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . '][' . $key . ']" type="checkbox" ' . checked($multi_stored[$key], true, false) . disabled(in_array($key, $disabledItems, false)) . ' /> <label for="' . $item['id'] . '_' . $key . '">' . $option . '</label></li>'; } $display .= '</ul>'; } } break; case 'range': $display .= '<input id="' . $item['id'] . '" class="fflcommerce-input fflcommerce-range ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']" type="range" min="' . $item['extra']['min'] . '" max="' . $item['extra']['max'] . '" step="' . $item['extra']['step'] . '" value="' . $options->get($item['id']) . '"' . $disabled . ' />'; break; case 'number': $display .= '<input id="' . $item['id'] . '" class="fflcommerce-input ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']" type="number" value="' . $options->get($item['id']) . '"'; if (isset($item['extra']['min'])) { $display .= ' min="' . $item['extra']['min'] . '"'; } if (isset($item['extra']['max'])) { $display .= ' max="' . $item['extra']['max'] . '"'; } if (isset($item['extra']['step'])) { $display .= ' step="' . $item['extra']['step'] . '"'; } $display .= $disabled . ' />'; break; case 'select': $multiple = !empty($item['multiple']) && $item['multiple'] == true ? 'multiple="multiple"' : ""; $brckt = ""; $width = 250; $selections = (array) $options->get($item['id']); if ($item['multiple']) { $brckt = "[]"; $width = 500; } $display .= '<select id="' . $item['id'] . '" class="fflcommerce-input fflcommerce-select ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']' . $brckt . '"' . $multiple . $disabled . ' >'; foreach ($item['choices'] as $value => $label) { if (is_array($label)) { $display .= '<optgroup label="' . $value . '">'; foreach ($label as $subValue => $subLabel) { $display .= '<option value="' . esc_attr($subValue) . '" ' . selected(in_array(esc_attr($subValue), $selections), true, false) . disabled(in_array($subValue, $disabledItems), true, false) . ' />' . $subLabel . '</option>'; } $display .= '</optgroup>'; } else { $display .= '<option value="' . esc_attr($value) . '" ' . selected(in_array(esc_attr($value), $selections), true, false) . disabled(in_array($value, $disabledItems), true, false) . ' />' . $label . '</option>'; } } $display .= '</select>'; $id = $item['id']; ?> <script type="text/javascript"> /*<![CDATA[*/ jQuery(function($){ $("#<?php echo $id; ?> ").select2({ width: '<?php echo $width; ?> px' }); }); /*]]>*/ </script> <?php break; default: fflcommerce_log("UNKOWN _type_ in Options parsing"); fflcommerce_log($item); } if ($item['type'] != 'tab') { if (empty($item['desc'])) { $explain_value = ''; } else { $explain_value = $item['desc']; } $display .= '<div class="fflcommerce-explain"><small>' . $explain_value . '</small></div></td>'; } return $display; }