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