Options_Framework_Interface

Generates the tabs that are used in the options menu.

Defined (1)

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

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