Options_Framework_Interface

The Onetone Options Framework Interface class.

Defined (1)

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

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