optionsframework_fields

Generates the options fields that are used in the form.

Description

optionsframework_fields(); 

Usage

  1. if ( !function_exists( 'optionsframework_fields' ) ) { 
  2. require_once '/admin/options-framework/options-interface.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = optionsframework_fields(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/admin/options-framework/options-interface.php  
  1. function optionsframework_fields() { 
  2.  
  3. global $allowedtags; 
  4. $optionsframework_settings = get_option('optionsframework'); 
  5.  
  6. // Gets the unique option id 
  7. if ( isset( $optionsframework_settings['id'] ) ) { 
  8. $option_name = $optionsframework_settings['id']; 
  9. else { 
  10. $option_name = 'optionsframework'; 
  11. }; 
  12.  
  13. $settings = get_option($option_name); 
  14. $options = optionsframework_options(); 
  15.  
  16. $counter = 0; 
  17. $menu = ''; 
  18.  
  19. foreach ( $options as $value ) { 
  20.  
  21. $counter++; 
  22. $val = ''; 
  23. $select_value = ''; 
  24. $checked = ''; 
  25. $output = ''; 
  26.  
  27. // Wrap all options 
  28. if ( ( $value['type'] != "heading" ) && ( $value['type'] != "info" ) ) { 
  29.  
  30. // Keep all ids lowercase with no spaces 
  31. $value['id'] = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($value['id']) ); 
  32.  
  33. $id = 'section-' . $value['id']; 
  34.  
  35. $class = 'section '; 
  36. if ( isset( $value['type'] ) ) { 
  37. $class .= ' section-' . $value['type']; 
  38. if ( isset( $value['class'] ) ) { 
  39. $class .= ' ' . $value['class']; 
  40.  
  41. $output .= '<div id="' . esc_attr( $id ) .'" class="' . esc_attr( $class ) . '">'."\n"; 
  42. if ( isset( $value['name'] ) ) { 
  43. $output .= '<h4 class="heading">' . esc_html( $value['name'] ) . '</h4>' . "\n"; 
  44. if ( $value['type'] != 'editor' ) { 
  45. $output .= '<div class="option">' . "\n" . '<div class="controls">' . "\n"; 
  46. else { 
  47. $output .= '<div class="option">' . "\n" . '<div>' . "\n"; 
  48.  
  49. // Set default value to $val 
  50. if ( isset( $value['std'] ) ) { 
  51. $val = $value['std']; 
  52.  
  53. // If the option is already saved, ovveride $val 
  54. if ( ( $value['type'] != 'heading' ) && ( $value['type'] != 'info') ) { 
  55. if ( isset( $settings[($value['id'])]) ) { 
  56. $val = $settings[($value['id'])]; 
  57. // Striping slashes of non-array options 
  58. if ( !is_array($val) ) { 
  59. $val = stripslashes( $val ); 
  60.  
  61. // If there is a description save it for labels 
  62. $explain_value = ''; 
  63. if ( isset( $value['desc'] ) ) { 
  64. $explain_value = $value['desc']; 
  65.  
  66. switch ( $value['type'] ) { 
  67.  
  68. // Basic text input 
  69. case 'text': 
  70. $output .= '<input id="' . esc_attr( $value['id'] ) . '" class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" type="text" value="' . esc_attr( $val ) . '" />'; 
  71. break; 
  72.  
  73. // Textarea 
  74. case 'textarea': 
  75. $rows = '8'; 
  76.  
  77. if ( isset( $value['settings']['rows'] ) ) { 
  78. $custom_rows = $value['settings']['rows']; 
  79. if ( is_numeric( $custom_rows ) ) { 
  80. $rows = $custom_rows; 
  81.  
  82. $val = stripslashes( $val ); 
  83. $output .= '<textarea id="' . esc_attr( $value['id'] ) . '" class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" rows="' . $rows . '">' . esc_textarea( $val ) . '</textarea>'; 
  84. break; 
  85.  
  86. // Select Box 
  87. case ($value['type'] == 'select'): 
  88. $output .= '<select class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" id="' . esc_attr( $value['id'] ) . '">'; 
  89.  
  90. foreach ($value['options'] as $key => $option ) { 
  91. $selected = ''; 
  92. if ( $val != '' ) { 
  93. if ( $val == $key) { $selected = ' selected="selected"';} 
  94. $output .= '<option'. $selected .' value="' . esc_attr( $key ) . '">' . esc_html( $option ) . '</option>'; 
  95. $output .= '</select>'; 
  96. break; 
  97.  
  98.  
  99. // Radio Box 
  100. case "radio": 
  101. $name = $option_name .'['. $value['id'] .']'; 
  102. foreach ($value['options'] as $key => $option) { 
  103. $id = $option_name . '-' . $value['id'] .'-'. $key; 
  104. $output .= '<input class="of-input of-radio" type="radio" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" value="'. esc_attr( $key ) . '" '. checked( $val, $key, false) .' /><label for="' . esc_attr( $id ) . '">' . esc_html( $option ) . '</label>'; 
  105. break; 
  106.  
  107. // Image Selectors 
  108. case "images": 
  109. $name = $option_name .'['. $value['id'] .']'; 
  110. foreach ( $value['options'] as $key => $option ) { 
  111. $selected = ''; 
  112. $checked = ''; 
  113. if ( $val != '' ) { 
  114. if ( $val == $key ) { 
  115. $selected = ' of-radio-img-selected'; 
  116. $checked = ' checked="checked"'; 
  117. $output .= '<input type="radio" id="' . esc_attr( $value['id'] .'_'. $key) . '" class="of-radio-img-radio" value="' . esc_attr( $key ) . '" name="' . esc_attr( $name ) . '" '. $checked .' />'; 
  118. $output .= '<div class="of-radio-img-label">' . esc_html( $key ) . '</div>'; 
  119. $output .= '<img src="' . esc_url( $option ) . '" alt="' . $option .'" class="of-radio-img-img' . $selected .'" onclick="document.getElementById(\''. esc_attr($value['id'] .'_'. $key) .'\').checked=true;" />'; 
  120. break; 
  121.  
  122. // Checkbox 
  123. case "checkbox": 
  124. $output .= '<input id="' . esc_attr( $value['id'] ) . '" class="checkbox of-input" type="checkbox" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" '. checked( $val, 1, false) .' />'; 
  125. $output .= '<label class="explain" for="' . esc_attr( $value['id'] ) . '">' . wp_kses( $explain_value, $allowedtags) . '</label>'; 
  126. break; 
  127.  
  128. // Multicheck 
  129. case "multicheck": 
  130. foreach ($value['options'] as $key => $option) { 
  131. $checked = ''; 
  132. $label = $option; 
  133. $option = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($key)); 
  134.  
  135. $id = $option_name . '-' . $value['id'] . '-'. $option; 
  136. $name = $option_name . '[' . $value['id'] . '][' . $option .']'; 
  137.  
  138. if ( isset($val[$option]) ) { 
  139. $checked = checked($val[$option], 1, false); 
  140.  
  141. $output .= '<input id="' . esc_attr( $id ) . '" class="checkbox of-input" type="checkbox" name="' . esc_attr( $name ) . '" ' . $checked . ' /><label for="' . esc_attr( $id ) . '">' . esc_html( $label ) . '</label>'; 
  142. break; 
  143.  
  144. // Color picker 
  145. case "color": 
  146. $output .= '<div id="' . esc_attr( $value['id'] . '_picker' ) . '" class="colorSelector"><div style="' . esc_attr( 'background-color:' . $val ) . '"></div></div>'; 
  147. $output .= '<input class="of-color" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" id="' . esc_attr( $value['id'] ) . '" type="text" value="' . esc_attr( $val ) . '" />'; 
  148. break; 
  149.  
  150. // Uploader 
  151. case "upload": 
  152. $output .= optionsframework_medialibrary_uploader( $value['id'], $val, null ); 
  153. break; 
  154.  
  155. // Typography 
  156. case 'typography': 
  157.  
  158. unset( $font_size, $font_style, $font_face, $font_color ); 
  159.  
  160. $typography_defaults = array( 
  161. 'size' => '',  
  162. 'face' => '',  
  163. 'style' => '',  
  164. 'color' => '' 
  165. ); 
  166.  
  167. $typography_stored = wp_parse_args( $val, $typography_defaults ); 
  168.  
  169. $typography_options = array( 
  170. 'sizes' => of_recognized_font_sizes(),  
  171. 'faces' => of_recognized_font_faces(),  
  172. 'styles' => of_recognized_font_styles(),  
  173. 'color' => true 
  174. ); 
  175.  
  176. if ( isset( $value['options'] ) ) { 
  177. $typography_options = wp_parse_args( $value['options'], $typography_options ); 
  178.  
  179. // Font Size 
  180. if ( $typography_options['sizes'] ) { 
  181. $font_size = '<select class="of-typography of-typography-size" name="' . esc_attr( $option_name . '[' . $value['id'] . '][size]' ) . '" id="' . esc_attr( $value['id'] . '_size' ) . '">'; 
  182. $sizes = $typography_options['sizes']; 
  183. foreach ( $sizes as $i ) { 
  184. $size = $i . 'px'; 
  185. $font_size .= '<option value="' . esc_attr( $size ) . '" ' . selected( $typography_stored['size'], $size, false ) . '>' . esc_html( $size ) . '</option>'; 
  186. $font_size .= '</select>'; 
  187.  
  188. // Font Face 
  189. if ( $typography_options['faces'] ) { 
  190. $font_face = '<select class="of-typography of-typography-face" name="' . esc_attr( $option_name . '[' . $value['id'] . '][face]' ) . '" id="' . esc_attr( $value['id'] . '_face' ) . '">'; 
  191. $faces = $typography_options['faces']; 
  192. foreach ( $faces as $key => $face ) { 
  193. $font_face .= '<option value="' . esc_attr( $key ) . '" ' . selected( $typography_stored['face'], $key, false ) . '>' . esc_html( $face ) . '</option>'; 
  194. $font_face .= '</select>'; 
  195.  
  196. // Font Styles 
  197. if ( $typography_options['styles'] ) { 
  198. $font_style = '<select class="of-typography of-typography-style" name="'.$option_name.'['.$value['id'].'][style]" id="'. $value['id'].'_style">'; 
  199. $styles = $typography_options['styles']; 
  200. foreach ( $styles as $key => $style ) { 
  201. $font_style .= '<option value="' . esc_attr( $key ) . '" ' . selected( $typography_stored['style'], $key, false ) . '>'. $style .'</option>'; 
  202. $font_style .= '</select>'; 
  203.  
  204. // Font Color 
  205. if ( $typography_options['color'] ) { 
  206. $font_color = '<div id="' . esc_attr( $value['id'] ) . '_color_picker" class="colorSelector"><div style="' . esc_attr( 'background-color:' . $typography_stored['color'] ) . '"></div></div>'; 
  207. $font_color .= '<input class="of-color of-typography of-typography-color" name="' . esc_attr( $option_name . '[' . $value['id'] . '][color]' ) . '" id="' . esc_attr( $value['id'] . '_color' ) . '" type="text" value="' . esc_attr( $typography_stored['color'] ) . '" />'; 
  208.  
  209. // Allow modification/injection of typography fields 
  210. $typography_fields = compact( 'font_size', 'font_face', 'font_style', 'font_color' ); 
  211. $typography_fields = apply_filters( 'of_typography_fields', $typography_fields, $typography_stored, $option_name, $value ); 
  212. $output .= implode( '', $typography_fields ); 
  213.  
  214. break; 
  215.  
  216. // Background 
  217. case 'background': 
  218.  
  219. $background = $val; 
  220.  
  221. // Background Color 
  222. $output .= '<div id="' . esc_attr( $value['id'] ) . '_color_picker" class="colorSelector"><div style="' . esc_attr( 'background-color:' . $background['color'] ) . '"></div></div>'; 
  223. $output .= '<input class="of-color of-background of-background-color" name="' . esc_attr( $option_name . '[' . $value['id'] . '][color]' ) . '" id="' . esc_attr( $value['id'] . '_color' ) . '" type="text" value="' . esc_attr( $background['color'] ) . '" />'; 
  224.  
  225. // Background Image - New AJAX Uploader using Media Library 
  226. if (!isset($background['image'])) { 
  227. $background['image'] = ''; 
  228.  
  229. $output .= optionsframework_medialibrary_uploader( $value['id'], $background['image'], null, '', 0, 'image'); 
  230. $class = 'of-background-properties'; 
  231. if ( '' == $background['image'] ) { 
  232. $class .= ' hide'; 
  233. $output .= '<div class="' . esc_attr( $class ) . '">'; 
  234.  
  235. // Background Repeat 
  236. $output .= '<select class="of-background of-background-repeat" name="' . esc_attr( $option_name . '[' . $value['id'] . '][repeat]' ) . '" id="' . esc_attr( $value['id'] . '_repeat' ) . '">'; 
  237.  
  238. foreach ($repeats as $key => $repeat) { 
  239. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['repeat'], $key, false ) . '>'. esc_html( $repeat ) . '</option>'; 
  240. $output .= '</select>'; 
  241.  
  242. // Background Position 
  243. $output .= '<select class="of-background of-background-position" name="' . esc_attr( $option_name . '[' . $value['id'] . '][position]' ) . '" id="' . esc_attr( $value['id'] . '_position' ) . '">'; 
  244.  
  245. foreach ($positions as $key=>$position) { 
  246. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['position'], $key, false ) . '>'. esc_html( $position ) . '</option>'; 
  247. $output .= '</select>'; 
  248.  
  249. // Background Attachment 
  250. $output .= '<select class="of-background of-background-attachment" name="' . esc_attr( $option_name . '[' . $value['id'] . '][attachment]' ) . '" id="' . esc_attr( $value['id'] . '_attachment' ) . '">'; 
  251.  
  252. foreach ($attachments as $key => $attachment) { 
  253. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['attachment'], $key, false ) . '>' . esc_html( $attachment ) . '</option>'; 
  254. $output .= '</select>'; 
  255. $output .= '</div>'; 
  256.  
  257. break; 
  258.  
  259. // Editor 
  260. case 'editor': 
  261. $output .= '<div class="explain">' . wp_kses( $explain_value, $allowedtags) . '</div>'."\n"; 
  262. echo $output; 
  263. $textarea_name = esc_attr( $option_name . '[' . $value['id'] . ']' ); 
  264. $default_editor_settings = array( 
  265. 'textarea_name' => $textarea_name,  
  266. 'media_buttons' => false,  
  267. 'tinymce' => array( 'plugins' => 'wordpress' ) 
  268. ); 
  269. $editor_settings = array(); 
  270. if ( isset( $value['settings'] ) ) { 
  271. $editor_settings = $value['settings']; 
  272. $editor_settings = array_merge($editor_settings, $default_editor_settings); 
  273. wp_editor( $val, $value['id'], $editor_settings ); 
  274. $output = ''; 
  275. break; 
  276.  
  277. // Info 
  278. case "info": 
  279. $id = ''; 
  280. $class = 'section'; 
  281. if ( isset( $value['id'] ) ) { 
  282. $id = 'id="' . esc_attr( $value['id'] ) . '" '; 
  283. if ( isset( $value['type'] ) ) { 
  284. $class .= ' section-' . $value['type']; 
  285. if ( isset( $value['class'] ) ) { 
  286. $class .= ' ' . $value['class']; 
  287.  
  288. $output .= '<div ' . $id . 'class="' . esc_attr( $class ) . '">' . "\n"; 
  289. if ( isset($value['name']) ) { 
  290. $output .= '<h4 class="heading">' . esc_html( $value['name'] ) . '</h4>' . "\n"; 
  291. if ( $value['desc'] ) { 
  292. $output .= apply_filters('of_sanitize_info', $value['desc'] ) . "\n"; 
  293. $output .= '</div>' . "\n"; 
  294. break; 
  295.  
  296. // Heading for Navigation 
  297. case "heading": 
  298. if ($counter >= 2) { 
  299. $output .= '</div>'."\n"; 
  300. $jquery_click_hook = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($value['name']) ); 
  301. $jquery_click_hook = "of-option-" . $jquery_click_hook; 
  302. $menu .= '<a id="'. esc_attr( $jquery_click_hook ) . '-tab" class="nav-tab" title="' . esc_attr( $value['name'] ) . '" href="' . esc_attr( '#'. $jquery_click_hook ) . '">' . esc_html( $value['name'] ) . '</a>'; 
  303. $output .= '<div class="group" id="' . esc_attr( $jquery_click_hook ) . '">'; 
  304. $output .= '<h3>' . esc_html( $value['name'] ) . '</h3>' . "\n"; 
  305. break; 
  306.  
  307. if ( ( $value['type'] != "heading" ) && ( $value['type'] != "info" ) ) { 
  308. $output .= '</div>'; 
  309. if ( ( $value['type'] != "checkbox" ) && ( $value['type'] != "editor" ) ) { 
  310. $output .= '<div class="explain">' . wp_kses( $explain_value, $allowedtags) . '</div>'."\n"; 
  311. $output .= '</div></div>'."\n"; 
  312.  
  313. echo $output; 
  314. echo '</div>';