* @license GPL-2.0+ * @link http://wptheming.com * @copyright 2010-2014 WP Theming */ class Options_Framework_Interface { /** * Generates the tabs that are used in the options menu */ public static function optionsframework_tabs() { $counter = 0; $options = &Options_Framework::_optionsframework_options(); $menu = ''; foreach ($options as $value) { // Heading for Navigation if ($value['type'] == "heading") { $counter++; $class = ''; $class = !empty($value['id']) ? $value['id'] : $value['name']; $class = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($class)) . '-tab'; $menu .= '' . esc_html($value['name']) . ''; } } return $menu; } /** * Generates the options fields that are used in the form. */ public static function optionsframework_fields() { global $allowedtags; $options_framework = new Options_Framework; $option_name = $options_framework->get_option_name(); $settings = get_option($option_name); $options = &Options_Framework::_optionsframework_options(); $counter = 0; $menu = ''; foreach ($options as $value) { $val = ''; $select_value = ''; $output = ''; // Wrap all options if (($value['type'] != "heading") && ($value['type'] != "info") && ($value['type'] != "about")) { // Keep all ids lowercase with no spaces $value['id'] = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($value['id'])); $id = 'section-' . $value['id']; $class = 'section'; if (isset($value['type'])) { $class .= ' section-' . $value['type']; } if (isset($value['class'])) { $class .= ' ' . $value['class']; } $output .= '
' . "\n"; if (isset($value['name'])) { $output .= '

' . esc_html($value['name']) . '

' . "\n"; } if ($value['type'] != 'editor') { $output .= '
' . "\n" . '
' . "\n"; } else { $output .= '
' . "\n" . '
' . "\n"; } } // Set default value to $val if (isset($value['std'])) { $val = $value['std']; } // If the option is already saved, override $val if (($value['type'] != 'heading') && ($value['type'] != 'info') && ($value['type'] != "about")) { if (isset($settings[($value['id'])])) { $val = $settings[($value['id'])]; // Striping slashes of non-array options if (!is_array($val)) { $val = stripslashes($val); } } } // If there is a description save it for labels $explain_value = ''; if (isset($value['desc'])) { $explain_value = $value['desc']; } // Set the placeholder if one exists $placeholder = ''; if (isset($value['placeholder'])) { $placeholder = ' placeholder="' . esc_attr($value['placeholder']) . '"'; } if (has_filter('optionsframework_' . $value['type'])) { $output .= apply_filters('optionsframework_' . $value['type'], $option_name, $value, $val); } switch ($value['type']) { // Basic text input case 'text': $output .= ''; break; // Password input case 'password': $output .= ''; break; // Textarea case 'textarea': $rows = '8'; if (isset($value['settings']['rows'])) { $custom_rows = $value['settings']['rows']; if (is_numeric($custom_rows)) { $rows = $custom_rows; } } $val = stripslashes($val); $output .= ''; break; // Raw code textarea(自定义 CSS / JS 用) // 这里必须直接读 $settings 拿原始值,不能用 $val: // 上面的公共逻辑对所有非数组值做了 stripslashes(),那是给老版本 // WP 入库带反斜杠的历史写法留的兼容;现在 options.php 已经 // wp_unslash 过,值本身是干净的,再剥一层会把 CSS 里合法的 // 转义(content: "\f101")和 JS 的 "\n" 啃坏。 case 'code': $rows = '10'; if (isset($value['settings']['rows'])) { $custom_rows = $value['settings']['rows']; if (is_numeric($custom_rows)) { $rows = $custom_rows; } } if (isset($settings[($value['id'])])) { $raw = $settings[($value['id'])]; } elseif (isset($value['std'])) { $raw = $value['std']; } else { $raw = ''; } if (!is_string($raw)) { $raw = ''; } $output .= ''; break; // Select Box case 'select': $output .= ''; break; // Radio Box case "radio": $name = $option_name . '[' . $value['id'] . ']'; foreach ($value['options'] as $key => $option) { $id = $option_name . '-' . $value['id'] . '-' . $key; $output .= ''; } break; // Image Selectors case "images": $name = $option_name . '[' . $value['id'] . ']'; foreach ($value['options'] as $key => $option) { $selected = ''; if ($val != '' && ($val == $key)) { $selected = ' of-radio-img-selected'; } $output .= ''; $output .= '
' . esc_html($key) . '
'; $output .= '' . $option . ''; } break; // Checkbox case "checkbox": $output .= ''; $output .= ''; break; // 多选复选框组 // // 框架原来只在保存侧处理了 multicheck(把未提交的项补 false), // **没有渲染分支、也没有 of_sanitize_multicheck**, // 所以这个类型此前是不可用的。这里补齐两处。 // // 值统一存成 array( 键 => 1|0 ),而不是「勾选了的键组成的列表」: // 用 map 才能区分「用户明确取消勾选」和「这个键是新增的」。 // 若存成列表,用户取消全部勾选后存进去是空数组, // 读的时候无法与「从未配置」区分,会静默回退到默认值。 case "multicheck": $name = $option_name . '[' . $value['id'] . ']'; $saved = is_array($val) ? $val : array(); if (!empty($value['options'])) { $output .= '
'; foreach ($value['options'] as $key => $opt) { $id = $option_name . '-' . $value['id'] . '-' . $key; $on = !empty($saved[$key]); $label = is_array($opt) && isset($opt['name']) ? $opt['name'] : $opt; $note = is_array($opt) && isset($opt['note']) ? $opt['note'] : ''; $output .= ''; } $output .= '
'; } break; // Color picker case "color": $default_color = ''; if (isset($value['std'])) { if ($val != $value['std']) { $default_color = ' data-default-color="' . $value['std'] . '" '; } } $output .= ''; break; // Uploader case "upload": $output .= Options_Framework_Media_Uploader::optionsframework_uploader($value['id'], $val, null); break; case "info": $id = ''; $class = 'section'; if (isset($value['id'])) { $id = 'id="' . esc_attr($value['id']) . '" '; } if (isset($value['type'])) { $class .= ' section-' . $value['type']; } if (isset($value['class'])) { $class .= ' ' . $value['class']; } $output .= '
' . "\n"; if (isset($value['name'])) { $output .= '

' . esc_html($value['name']) . '

' . "\n"; } if (isset($value['desc'])) { $output .= $value['desc'] . "\n"; } $output .= '
' . "\n"; break; case "sendmail": $output .= ''; break; // Heading for Navigation case "heading": $counter++; if ($counter >= 2) { $output .= '
' . "\n"; } $class = ''; $class = !empty($value['id']) ? $value['id'] : $value['name']; $class = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($class)); $output .= '
'; $output .= '

' . esc_html($value['name']) . '

' . "\n"; break; } if (($value['type'] != "heading") && ($value['type'] != "info") && ($value['type'] != "about")) { $output .= '
'; if (($value['type'] != "checkbox") && ($value['type'] != "editor")) { $output .= '
' . wp_kses($explain_value, $allowedtags) . '
' . "\n"; } $output .= '
' . "\n"; } echo $output; } // Outputs closing div if there tabs if (Options_Framework_Interface::optionsframework_tabs() != '') { echo '
'; } } }