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. break; 
  184.  
  185. // Typography 
  186. case 'typography': 
  187.  
  188. unset( $font_size, $font_style, $font_face, $font_color ); 
  189.  
  190. $typography_defaults = array( 
  191. 'size' => '',  
  192. 'face' => '',  
  193. 'style' => '',  
  194. 'color' => '' 
  195. ); 
  196.  
  197. $typography_stored = wp_parse_args( $val, $typography_defaults ); 
  198.  
  199. $typography_options = array( 
  200. 'sizes' => of_recognized_font_sizes(),  
  201. 'faces' => of_recognized_font_faces(),  
  202. 'styles' => of_recognized_font_styles(),  
  203. 'color' => true 
  204. ); 
  205.  
  206. if ( isset( $value['options'] ) ) { 
  207. $typography_options = wp_parse_args( $value['options'], $typography_options ); 
  208.  
  209. // Font Size 
  210. if ( $typography_options['sizes'] ) { 
  211. $font_size = '<select class="of-typography of-typography-size" name="' . esc_attr( $option_name . '[' . $value['id'] . '][size]' ) . '" id="' . esc_attr( $value['id'] . '_size' ) . '">'; 
  212. $sizes = $typography_options['sizes']; 
  213. foreach ( $sizes as $i ) { 
  214. $size = $i . 'px'; 
  215. $font_size .= '<option value="' . esc_attr( $size ) . '" ' . selected( $typography_stored['size'], $size, false ) . '>' . esc_html( $size ) . '</option>'; 
  216. $font_size .= '</select>'; 
  217.  
  218. // Font Face 
  219. if ( $typography_options['faces'] ) { 
  220. $font_face = '<select class="of-typography of-typography-face" name="' . esc_attr( $option_name . '[' . $value['id'] . '][face]' ) . '" id="' . esc_attr( $value['id'] . '_face' ) . '">'; 
  221. $faces = $typography_options['faces']; 
  222. foreach ( $faces as $key => $face ) { 
  223. $font_face .= '<option value="' . esc_attr( $key ) . '" ' . selected( $typography_stored['face'], $key, false ) . '>' . esc_html( $face ) . '</option>'; 
  224. $font_face .= '</select>'; 
  225.  
  226. // Font Styles 
  227. if ( $typography_options['styles'] ) { 
  228. $font_style = '<select class="of-typography of-typography-style" name="'.$option_name.'['.$value['id'].'][style]" id="'. $value['id'].'_style">'; 
  229. $styles = $typography_options['styles']; 
  230. foreach ( $styles as $key => $style ) { 
  231. $font_style .= '<option value="' . esc_attr( $key ) . '" ' . selected( $typography_stored['style'], $key, false ) . '>'. $style .'</option>'; 
  232. $font_style .= '</select>'; 
  233.  
  234. // Font Color 
  235. if ( $typography_options['color'] ) { 
  236. $default_color = ''; 
  237. if ( isset($value['std']['color']) ) { 
  238. if ( $val != $value['std']['color'] ) 
  239. $default_color = ' data-default-color="' .$value['std']['color'] . '" '; 
  240. $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 .' />'; 
  241.  
  242. // Allow modification/injection of typography fields 
  243. $typography_fields = compact( 'font_size', 'font_face', 'font_style', 'font_color' ); 
  244. $typography_fields = apply_filters( 'of_typography_fields', $typography_fields, $typography_stored, $option_name, $value ); 
  245. $output .= implode( '', $typography_fields ); 
  246.  
  247. break; 
  248.  
  249. // Background 
  250. case 'background': 
  251.  
  252. $background = $val; 
  253.  
  254. // Background Color 
  255. $default_color = ''; 
  256. if ( isset( $value['std']['color'] ) ) { 
  257. if ( $val != $value['std']['color'] ) 
  258. $default_color = ' data-default-color="' .$value['std']['color'] . '" '; 
  259. $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 .' />'; 
  260.  
  261. // Background Image 
  262. if ( !isset($background['image']) ) { 
  263. $background['image'] = ''; 
  264.  
  265. $output .= Options_Framework_Media_Uploader::optionsframework_uploader( $value['id'], $background['image'], null, esc_attr( $option_name . '[' . $value['id'] . '][image]' ) ); 
  266.  
  267. $class = 'of-background-properties'; 
  268. if ( '' == $background['image'] ) { 
  269. $class .= ' hide'; 
  270. $output .= '<div class="' . esc_attr( $class ) . '">'; 
  271.  
  272. // Background Repeat 
  273. $output .= '<select class="of-background of-background-repeat" name="' . esc_attr( $option_name . '[' . $value['id'] . '][repeat]' ) . '" id="' . esc_attr( $value['id'] . '_repeat' ) . '">'; 
  274. $repeats = of_recognized_background_repeat(); 
  275.  
  276. foreach ($repeats as $key => $repeat) { 
  277. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['repeat'], $key, false ) . '>'. esc_html( $repeat ) . '</option>'; 
  278. $output .= '</select>'; 
  279.  
  280. // Background Position 
  281. $output .= '<select class="of-background of-background-position" name="' . esc_attr( $option_name . '[' . $value['id'] . '][position]' ) . '" id="' . esc_attr( $value['id'] . '_position' ) . '">'; 
  282. $positions = of_recognized_background_position(); 
  283.  
  284. foreach ($positions as $key=>$position) { 
  285. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['position'], $key, false ) . '>'. esc_html( $position ) . '</option>'; 
  286. $output .= '</select>'; 
  287.  
  288. // Background Attachment 
  289. $output .= '<select class="of-background of-background-attachment" name="' . esc_attr( $option_name . '[' . $value['id'] . '][attachment]' ) . '" id="' . esc_attr( $value['id'] . '_attachment' ) . '">'; 
  290. $attachments = of_recognized_background_attachment(); 
  291.  
  292. foreach ($attachments as $key => $attachment) { 
  293. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['attachment'], $key, false ) . '>' . esc_html( $attachment ) . '</option>'; 
  294. $output .= '</select>'; 
  295. $output .= '</div>'; 
  296.  
  297. break; 
  298.  
  299. // Editor 
  300. case 'editor': 
  301. $output .= '<div class="explain">' . wp_kses( $explain_value, $allowedtags ) . '</div>'."\n"; 
  302. echo $output; 
  303. $textarea_name = esc_attr( $option_name . '[' . $value['id'] . ']' ); 
  304. $default_editor_settings = array( 
  305. 'textarea_name' => $textarea_name,  
  306. 'media_buttons' => false,  
  307. 'tinymce' => array( 'plugins' => 'wordpress' ) 
  308. ); 
  309. $editor_settings = array(); 
  310. if ( isset( $value['settings'] ) ) { 
  311. $editor_settings = $value['settings']; 
  312. $editor_settings = array_merge( $default_editor_settings, $editor_settings ); 
  313. wp_editor( $val, $value['id'], $editor_settings ); 
  314. $output = ''; 
  315. break; 
  316.  
  317. // Info 
  318. case "info": 
  319. $id = ''; 
  320. $class = 'section'; 
  321. if ( isset( $value['id'] ) ) { 
  322. $id = 'id="' . esc_attr( $value['id'] ) . '" '; 
  323. if ( isset( $value['type'] ) ) { 
  324. $class .= ' section-' . $value['type']; 
  325. if ( isset( $value['class'] ) ) { 
  326. $class .= ' ' . $value['class']; 
  327.  
  328. $output .= '<div ' . $id . 'class="' . esc_attr( $class ) . '">' . "\n"; 
  329. if ( isset($value['name']) ) { 
  330. $output .= '<h4 class="heading">' . esc_html( $value['name'] ) . '</h4>' . "\n"; 
  331. if ( isset( $value['desc'] ) ) { 
  332. $output .= $value['desc'] . "\n"; 
  333. $output .= '</div>' . "\n"; 
  334. break; 
  335.  
  336. // Heading for Navigation 
  337. case "heading": 
  338. $counter++; 
  339. if ( $counter >= 2 ) { 
  340. $output .= '</div>'."\n"; 
  341. $class = ''; 
  342. $class = ! empty( $value['id'] ) ? $value['id'] : $value['name']; 
  343. $class = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($class) ); 
  344. $output .= '<div id="options-group-' . $counter . '" class="group ' . $class . '">'; 
  345. $output .= '<h3>' . esc_html( $value['name'] ) . '</h3>' . "\n"; 
  346. break; 
  347.  
  348. if ( ( $value['type'] != "heading" ) && ( $value['type'] != "info" ) ) { 
  349. $output .= '</div>'; 
  350. if ( ( $value['type'] != "checkbox" ) && ( $value['type'] != "editor" ) ) { 
  351. $output .= '<div class="explain">' . wp_kses( $explain_value, $allowedtags) . '</div>'."\n"; 
  352. $output .= '</div></div>'."\n"; 
  353.  
  354. echo $output; 
  355.  
  356. // Outputs closing div if there tabs 
  357. if ( Options_Framework_Interface::optionsframework_tabs() != '' ) { 
  358. echo '</div>'; 
  359.