Onetone_Customizer

The Onetone Onetone Customizer class.

Defined (1)

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

/lib/customizer/customizer.php  
  1. class Onetone_Customizer { 
  2.  
  3. protected static $default_data = array( 
  4. 'default' => '',  
  5. 'slug' => '',  
  6. 'panel' => '',  
  7. 'label' => '',  
  8. 'description' => '',  
  9. 'transport' => 'refresh',  
  10. 'priority' => '',  
  11. 'type' => 'color',  
  12. 'selector' => '',  
  13. 'property' => '',  
  14. 'property2' => '',  
  15. 'output' => true,  
  16. 'font_amount' => 500,  
  17. ); 
  18.  
  19. function __construct() { 
  20.  
  21. $this->onetone_define_constants(); 
  22. $this->onetone_load_custom_controls(); 
  23. $this->onetone_load_customizer_data(); 
  24. add_action( 'customize_register', array( &$this, 'onetone_theme_customizer_register' ), 10 ); 
  25. add_action( 'customize_preview_init', array( &$this, 'onetone_customizer_live_preview' ) , 1 ); 
  26. add_action( 'wp_head', array( &$this, 'onetone_customizer_print_css' ), 10 ); 
  27. add_action( 'wp_head', array( &$this, 'onetone_customizer_font_output' ), 15 ); 
  28. add_action( 'customize_controls_enqueue_scripts', array( &$this, 'onetone_customizer_enqueue_scripts' ), 20 ); 
  29.  
  30. /** 
  31. * Define constants 
  32. **/ 
  33. function onetone_define_constants() { 
  34. if ( ! defined( 'ONETONE_DIR' ) ) define( 'ONETONE_DIR', trailingslashit( get_template_directory() . '/lib/customizer' ) ); 
  35. if ( ! defined( 'ONETONE_URI' ) )define( 'ONETONE_URI', trailingslashit( get_template_directory_uri() . '/lib/customizer' ) ); 
  36.  
  37. /** 
  38. * Automatically load all custom control files 
  39. **/ 
  40. function onetone_load_custom_controls() { 
  41. foreach ( glob( ONETONE_DIR . "includes/*.php" ) as $filename ) { 
  42. include $filename; 
  43.   
  44. /** 
  45. * Load customizer file 
  46. * @return void 
  47. * @author  
  48. **/ 
  49. function onetone_load_customizer_data() { 
  50. require_once ONETONE_DIR . '/customizer-data.php'; 
  51.  
  52. /** 
  53. * Get all registered data 
  54. */ 
  55. function onetone_get_customizer_data() { 
  56. $onetone_options= array(); 
  57. return apply_filters( 'onetone_customizer_data', $onetone_options ); 
  58.  
  59. /** 
  60. * Register Custom Sections, Settings, And Controls 
  61. */ 
  62. function onetone_theme_customizer_register( $wp_customize ) { 
  63.  
  64. $onetone_get_data = array(); 
  65. $onetone_data = $this->onetone_get_customizer_data( $onetone_get_data ); 
  66. //create the componen from array data 
  67. foreach ( $onetone_data as $data ) { 
  68.  
  69. $data = wp_parse_args( $data, self::$default_data ); 
  70.  
  71. // Define each customizer type  
  72. switch ( $data['type'] ) { 
  73.  
  74. case 'panel': 
  75. // Add Panel 
  76. $wp_customize->add_panel( $data['slug'], array( 
  77. 'priority' => $data['priority'],  
  78. 'capability' => 'edit_theme_options',  
  79. 'theme_supports' => '',  
  80. 'title' => $data['label'],  
  81. 'description' => $data['description'],  
  82. ) ); 
  83.  
  84. break; 
  85.  
  86. case 'section': 
  87. // Add Section 
  88. $wp_customize->add_section( $data['slug'],  
  89. array( 
  90. 'title' => $data['label'],  
  91. 'priority' => $data['priority'],  
  92. 'panel' => $data['panel'] 
  93. )); 
  94. break; 
  95.  
  96. case 'color': 
  97. case 'color_rgb': 
  98. $wp_customize->add_setting( $data['slug'],  
  99. array(  
  100. 'default' => $data['default'],  
  101. 'type' => 'option',  
  102. 'capability' => 'edit_theme_options',  
  103. 'transport' => $data['transport'],  
  104. 'sanitize_callback' => 'sanitize_hex_color',  
  105. )  
  106. ); 
  107. $wp_customize->add_control( new WP_Customize_Color_Control(  
  108. $wp_customize, $data['slug'],  
  109. array(  
  110. 'label' => $data['label'],  
  111. 'description' => $data['description'],  
  112. 'section' => $data['section'],  
  113. 'priority' => $data['priority'],  
  114. 'settings' => $data['slug']  
  115. )  
  116. )); 
  117. break; 
  118.  
  119. case 'text' : 
  120. $wp_customize->add_setting( $data['slug'],  
  121. array( 
  122. 'default' => $data['default'],  
  123. 'type' => 'option',  
  124. 'capability' => 'edit_theme_options',  
  125. 'transport' => $data['transport'],  
  126. 'sanitize_callback' => 'sanitize_text_field',  
  127. ) ); 
  128. $wp_customize->add_control(  
  129. $data['slug'],  
  130. array(  
  131. 'label' => $data['label'],  
  132. 'description' => $data['description'],  
  133. 'section' => $data['section'],  
  134. 'default' => $data['default'],  
  135. 'priority' => $data['priority'],  
  136. 'settings' => $data['slug'],  
  137. 'type' => 'text' 
  138. ); 
  139. break; 
  140.  
  141. case 'email' : 
  142. $wp_customize->add_setting( $data['slug'],  
  143. array( 
  144. 'default' => $data['default'],  
  145. 'type' => 'option',  
  146. 'capability' => 'edit_theme_options',  
  147. 'transport' => $data['transport'],  
  148. 'sanitize_callback' => 'sanitize_email',  
  149. ) ); 
  150. $wp_customize->add_control( 
  151. $data['slug'],  
  152. array(  
  153. 'label' => $data['label'],  
  154. 'description' => $data['description'],  
  155. 'section' => $data['section'],  
  156. 'default' => $data['default'],  
  157. 'priority' => $data['priority'],  
  158. 'settings' => $data['slug'],  
  159. 'type' => 'email' 
  160. ); 
  161. break; 
  162.  
  163. case 'url' : 
  164. $wp_customize->add_setting( $data['slug'],  
  165. array( 
  166. 'default' => $data['default'],  
  167. 'type' => 'option',  
  168. 'capability' => 'edit_theme_options',  
  169. 'transport' => $data['transport'],  
  170. 'sanitize_callback' => 'esc_url',  
  171. ) ); 
  172. $wp_customize->add_control( 
  173. $data['slug'],  
  174. array(  
  175. 'label' => $data['label'],  
  176. 'description' => $data['description'],  
  177. 'section' => $data['section'],  
  178. 'default' => $data['default'],  
  179. 'priority' => $data['priority'],  
  180. 'settings' => $data['slug'],  
  181. 'type' => 'url' 
  182. ); 
  183. break; 
  184.  
  185. case 'password' : 
  186. $wp_customize->add_setting( $data['slug'],  
  187. array( 
  188. 'default' => $data['default'],  
  189. 'type' => 'option',  
  190. 'capability' => 'edit_theme_options',  
  191. 'transport' => $data['transport'],  
  192. 'sanitize_callback' => 'sanitize_text_field',  
  193. ) ); 
  194. $wp_customize->add_control( 
  195. $data['slug'],  
  196. array(  
  197. 'label' => $data['label'],  
  198. 'description' => $data['description'],  
  199. 'section' => $data['section'],  
  200. 'default' => $data['default'],  
  201. 'priority' => $data['priority'],  
  202. 'settings' => $data['slug'],  
  203. 'type' => 'password' 
  204. ); 
  205. break; 
  206.  
  207. case 'textarea' : 
  208. $wp_customize->add_setting( $data['slug'],  
  209. array( 
  210. 'default' => $data['default'],  
  211. 'type' => 'option',  
  212. 'capability' => 'edit_theme_options',  
  213. 'transport' => $data['transport'],  
  214. 'sanitize_callback' => 'wp_kses_post',  
  215. ) ); 
  216. $wp_customize->add_control( 
  217. $data['slug'],  
  218. array(  
  219. 'label' => $data['label'],  
  220. 'description' => $data['description'],  
  221. 'section' => $data['section'],  
  222. 'default' => $data['default'],  
  223. 'priority' => $data['priority'],  
  224. 'settings' => $data['slug'],  
  225. 'type' => 'textarea' 
  226. ); 
  227. break; 
  228.  
  229. case 'date' : 
  230. $wp_customize->add_setting( $data['slug'],  
  231. array( 
  232. 'default' => $data['default'],  
  233. 'type' => 'option',  
  234. 'capability' => 'edit_theme_options',  
  235. 'transport' => $data['transport'],  
  236. 'sanitize_callback' => 'sanitize_text_field',  
  237. ) ); 
  238. $wp_customize->add_control( 
  239. $data['slug'],  
  240. array(  
  241. 'label' => $data['label'],  
  242. 'description' => $data['description'],  
  243. 'section' => $data['section'],  
  244. 'default' => $data['default'],  
  245. 'priority' => $data['priority'],  
  246. 'settings' => $data['slug'],  
  247. 'type' => 'date' 
  248. ); 
  249. break; 
  250.  
  251. case 'select' : 
  252. $wp_customize->add_setting( $data['slug'],  
  253. array( 
  254. 'default' => $data['default'],  
  255. 'type' => 'option',  
  256. 'transport' => $data['transport'],  
  257. 'capability' => 'edit_theme_options',  
  258. 'sanitize_callback' => 'esc_attr',  
  259. ) ); 
  260. $wp_customize->add_control(  
  261. $data['slug'],  
  262. array(  
  263. 'label' => $data['label'],  
  264. 'description' => $data['description'],  
  265. 'section' => $data['section'],  
  266. 'default' => $data['default'],  
  267. 'priority' => $data['priority'],  
  268. 'settings' => $data['slug'],  
  269. 'choices' => $data['choices'],  
  270. 'type' => 'select' 
  271. ); 
  272. break; 
  273.  
  274. case 'radio' : 
  275. $wp_customize->add_setting( $data['slug'],  
  276. array( 
  277. 'default' => $data['default'],  
  278. 'type' => 'option',  
  279. 'transport' => $data['transport'],  
  280. 'capability' => 'edit_theme_options',  
  281. 'sanitize_callback' => 'esc_attr',  
  282. ) ); 
  283. $wp_customize->add_control(  
  284. $data['slug'],  
  285. array(  
  286. 'label' => $data['label'],  
  287. 'description' => $data['description'],  
  288. 'section' => $data['section'],  
  289. 'default' => $data['default'],  
  290. 'priority' => $data['priority'],  
  291. 'settings' => $data['slug'],  
  292. 'choices' => $data['choices'],  
  293. 'type' => 'radio' 
  294. ); 
  295. break; 
  296.  
  297. case 'dropdown-pages' : 
  298. $wp_customize->add_setting( $data['slug'],  
  299. array( 
  300. 'default' => $data['default'],  
  301. 'type' => 'option',  
  302. 'transport' => $data['transport'],  
  303. 'capability' => 'edit_theme_options',  
  304. 'sanitize_callback' => 'esc_attr',  
  305. ) ); 
  306. $wp_customize->add_control( 
  307. $data['slug'],  
  308. array(  
  309. 'label' => $data['label'],  
  310. 'description' => $data['description'],  
  311. 'section' => $data['section'],  
  312. 'default' => $data['default'],  
  313. 'priority' => $data['priority'],  
  314. 'settings' => $data['slug'],  
  315. 'type' => 'dropdown-pages' 
  316. ); 
  317. break; 
  318.  
  319. case 'checkbox' : 
  320. $wp_customize->add_setting( $data['slug'],  
  321. array( 
  322. 'default' => $data['default'],  
  323. 'type' => 'option',  
  324. 'transport' => $data['transport'],  
  325. 'capability' => 'edit_theme_options',  
  326. 'sanitize_callback' => 'esc_attr',  
  327. ) ); 
  328. $wp_customize->add_control( 
  329. $data['slug'],  
  330. array(  
  331. 'label' => $data['label'],  
  332. 'description' => $data['description'],  
  333. 'section' => $data['section'],  
  334. 'default' => $data['default'],  
  335. 'priority' => $data['priority'],  
  336. 'settings' => $data['slug'],  
  337. 'type' => 'checkbox' 
  338. ); 
  339. break; 
  340.  
  341. case 'images' : 
  342. $wp_customize->add_setting( $data['slug'],  
  343. array(  
  344. 'default' => $data['default'],  
  345. 'capability' => 'edit_theme_options',  
  346. 'type' => 'option',  
  347. 'sanitize_callback' => 'esc_url_raw',  
  348. ));  
  349. $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize,  
  350. $data['slug'],  
  351. array(  
  352. 'label' => $data['label'],  
  353. 'description' => $data['description'],  
  354. 'section' => $data['section'],  
  355. 'priority' => $data['priority'],  
  356. 'settings' => $data['slug'] 
  357. ))); 
  358. break; 
  359.  
  360. case 'image_select' : 
  361. $wp_customize->add_setting( $data['slug'],  
  362. array(  
  363. 'default' => $data['default'],  
  364. 'capability' => 'edit_theme_options',  
  365. 'type' => 'option',  
  366. 'sanitize_callback' => 'esc_attr',  
  367. ));  
  368. $wp_customize->add_control( new Image_Select_Control( $wp_customize,  
  369. $data['slug'],  
  370. array(  
  371. 'label' => $data['label'],  
  372. 'description' => $data['description'],  
  373. 'section' => $data['section'],  
  374. 'priority' => $data['priority'],  
  375. 'settings' => $data['slug'],  
  376. 'choices' => $data['choices'] 
  377. ))); 
  378. break; 
  379.  
  380. case 'file' : 
  381. $wp_customize->add_setting( $data['slug'],  
  382. array(  
  383. 'default' => $data['default'],  
  384. 'capability' => 'edit_theme_options',  
  385. 'type' => 'option',  
  386. 'sanitize_callback' => 'esc_url_raw',  
  387. ));  
  388. $wp_customize->add_control( new WP_Customize_Upload_Control( $wp_customize,  
  389. $data['slug'],  
  390. array(  
  391. 'label' => $data['label'],  
  392. 'description' => $data['description'],  
  393. 'section' => $data['section'],  
  394. 'priority' => $data['priority'],  
  395. 'settings' => $data['slug'] 
  396. ))); 
  397. break; 
  398.  
  399. case 'category_dropdown' : 
  400. $wp_customize->add_setting( $data['slug'],  
  401. array(  
  402. 'default' => $data['default'],  
  403. 'capability' => 'edit_theme_options',  
  404. 'type' => 'option',  
  405. 'sanitize_callback' => 'esc_attr',  
  406. ));  
  407. $wp_customize->add_control( new Category_Dropdown_Custom_Control( $wp_customize,  
  408. $data['slug'],  
  409. array(  
  410. 'label' => $data['label'],  
  411. 'description' => $data['description'],  
  412. 'section' => $data['section'],  
  413. 'priority' => $data['priority'],  
  414. 'settings' => $data['slug'] 
  415. ))); 
  416. break; 
  417.  
  418. case 'menu_dropdown' : 
  419. $wp_customize->add_setting( $data['slug'],  
  420. array(  
  421. 'default' => $data['default'],  
  422. 'capability' => 'edit_theme_options',  
  423. 'type' => 'option',  
  424. 'sanitize_callback' => 'esc_attr',  
  425. ));  
  426. $wp_customize->add_control( new Menu_Dropdown_Custom_Control( $wp_customize,  
  427. $data['slug'],  
  428. array(  
  429. 'label' => $data['label'],  
  430. 'description' => $data['description'],  
  431. 'section' => $data['section'],  
  432. 'priority' => $data['priority'],  
  433. 'settings' => $data['slug'] 
  434. ))); 
  435. break; 
  436.  
  437. case 'post_dropdown' : 
  438. $wp_customize->add_setting( $data['slug'],  
  439. array(  
  440. 'default' => $data['default'],  
  441. 'capability' => 'edit_theme_options',  
  442. 'type' => 'option',  
  443. 'sanitize_callback' => 'esc_attr',  
  444. ));  
  445. $wp_customize->add_control( new Post_Dropdown_Custom_Control( $wp_customize,  
  446. $data['slug'],  
  447. array(  
  448. 'label' => $data['label'],  
  449. 'description' => $data['description'],  
  450. 'section' => $data['section'],  
  451. 'priority' => $data['priority'],  
  452. 'settings' => $data['slug'] 
  453. ))); 
  454. break; 
  455.  
  456. case 'post_type_dropdown' : 
  457. $wp_customize->add_setting( $data['slug'],  
  458. array(  
  459. 'default' => $data['default'],  
  460. 'capability' => 'edit_theme_options',  
  461. 'type' => 'option',  
  462. 'sanitize_callback' => 'esc_attr',  
  463. ));  
  464. $wp_customize->add_control( new Post_Type_Dropdown_Custom_Control( $wp_customize,  
  465. $data['slug'],  
  466. array(  
  467. 'label' => $data['label'],  
  468. 'description' => $data['description'],  
  469. 'section' => $data['section'],  
  470. 'priority' => $data['priority'],  
  471. 'settings' => $data['slug'] 
  472. ))); 
  473. break; 
  474.  
  475. case 'dropdown_user' : 
  476. $wp_customize->add_setting( $data['slug'],  
  477. array(  
  478. 'default' => $data['default'],  
  479. 'capability' => 'edit_theme_options',  
  480. 'type' => 'option',  
  481. 'sanitize_callback' => 'esc_attr',  
  482. ));  
  483. $wp_customize->add_control( new User_Dropdown_Custom_Control( $wp_customize,  
  484. $data['slug'],  
  485. array(  
  486. 'label' => $data['label'],  
  487. 'description' => $data['description'],  
  488. 'section' => $data['section'],  
  489. 'priority' => $data['priority'],  
  490. 'settings' => $data['slug'] 
  491. ))); 
  492. break; 
  493.  
  494. case 'editor' : 
  495. $wp_customize->add_setting( $data['slug'],  
  496. array(  
  497. 'default' => $data['default'],  
  498. 'capability' => 'edit_theme_options',  
  499. 'type' => 'option',  
  500. 'sanitize_callback' => 'esc_textarea',  
  501. ));  
  502. $wp_customize->add_control( new Text_Editor_Custom_Control( $wp_customize,  
  503. $data['slug'],  
  504. array(  
  505. 'label' => $data['label'],  
  506. 'description' => $data['description'],  
  507. 'section' => $data['section'],  
  508. 'priority' => $data['priority'],  
  509. 'settings' => $data['slug'] 
  510. ))); 
  511. break; 
  512.  
  513. case 'google_font' : 
  514. $wp_customize->add_setting( $data['slug'],  
  515. array(  
  516. 'default' => $data['default'],  
  517. 'capability' => 'edit_theme_options',  
  518. 'type' => 'option',  
  519. 'sanitize_callback' => 'esc_attr',  
  520. ));  
  521. $wp_customize->add_control( new Google_Font_Dropdown_Custom_Control( $wp_customize,  
  522. $data['slug'],  
  523. array(  
  524. 'label' => $data['label'],  
  525. 'description' => $data['description'],  
  526. 'section' => $data['section'],  
  527. 'priority' => $data['priority'],  
  528. 'settings' => $data['slug'],  
  529. 'amount' => $data['font_amount'] 
  530. ))); 
  531. break; 
  532.  
  533. case 'select_chosen' : 
  534. $wp_customize->add_setting( $data['slug'],  
  535. array(  
  536. 'default' => $data['default'],  
  537. 'capability' => 'edit_theme_options',  
  538. 'type' => 'option',  
  539. 'sanitize_callback' => 'esc_attr',  
  540. ));  
  541. $wp_customize->add_control( new Chosen_Custom_Control( $wp_customize,  
  542. $data['slug'],  
  543. array(  
  544. 'label' => $data['label'],  
  545. 'description' => $data['description'],  
  546. 'section' => $data['section'],  
  547. 'priority' => $data['priority'],  
  548. 'settings' => $data['slug'],  
  549. 'choices' => $data['choices'],  
  550. ))); 
  551. break; 
  552.  
  553. case 'image_select' : 
  554. $wp_customize->add_setting( $data['slug'],  
  555. array(  
  556. 'default' => $data['default'],  
  557. 'capability' => 'edit_theme_options',  
  558. 'type' => 'option',  
  559. 'sanitize_callback' => 'esc_attr',  
  560. ));  
  561. $wp_customize->add_control( new Image_Select_Control( $wp_customize,  
  562. $data['slug'],  
  563. array(  
  564. 'label' => $data['label'],  
  565. 'description' => $data['description'],  
  566. 'section' => $data['section'],  
  567. 'priority' => $data['priority'],  
  568. 'settings' => $data['slug'],  
  569. 'choices' => $data['choices'] 
  570. ))); 
  571. break; 
  572.  
  573. case 'buttonset' : 
  574. $wp_customize->add_setting( $data['slug'],  
  575. array( 
  576. 'default' => $data['default'],  
  577. 'type' => 'option',  
  578. 'transport' => $data['transport'],  
  579. 'capability' => 'edit_theme_options',  
  580. 'sanitize_callback' => 'esc_attr',  
  581. ) ); 
  582. $wp_customize->add_control( new Buttonset_Custom_Control( $wp_customize,  
  583. $data['slug'],  
  584. array(  
  585. 'label' => $data['label'],  
  586. 'description' => $data['description'],  
  587. 'section' => $data['section'],  
  588. 'default' => $data['default'],  
  589. 'priority' => $data['priority'],  
  590. 'settings' => $data['slug'],  
  591. 'choices' => $data['choices'],  
  592. 'type' => 'buttonset' 
  593. )); 
  594. break; 
  595.  
  596. default: 
  597. break; 
  598.  
  599. /** 
  600. * Used by hook: 'customize_preview_init' 
  601. * @see add_action( 'customize_preview_init', $func ) 
  602. */ 
  603. function onetone_customizer_live_preview() { 
  604.  
  605. $onetone_options = array(); 
  606. $onetone_options = $this->onetone_get_customizer_data( $onetone_options ); 
  607.  
  608. wp_enqueue_script( 'customizer-preview', ONETONE_URI . 'assets/js/customizer-preview.js', array( 'jquery', 'customize-preview' ), '', true ); 
  609. wp_localize_script( 'customizer-preview', 'onetoneStyle', $onetone_options ); 
  610.  
  611.  
  612. /** 
  613. * Enqueue Scripts 
  614. * @return void 
  615. **/ 
  616. function onetone_customizer_enqueue_scripts() { 
  617. $onetone_options = array(); 
  618. $onetone_options = $this->onetone_get_customizer_data( $onetone_options ); 
  619.  
  620. wp_enqueue_script( 'onetone-customizer-plugins', ONETONE_URI . 'assets/js/plugins.min.js', array( 'jquery' ), '', true ); 
  621. wp_enqueue_script( 'onetone-customizer-methods', ONETONE_URI . 'assets/js/methods.js', array( 'jquery' ), '', true ); 
  622. wp_localize_script( 'onetone-customizer-methods', 'onetoneScript', $onetone_options ); 
  623. wp_enqueue_style( 'onetone-customizer-style', ONETONE_URI . 'assets/css/styles.css' ); 
  624. wp_enqueue_style( 'onetone-customizer-plugins', ONETONE_URI . 'assets/css/plugins.min.css' ); 
  625.  
  626. wp_enqueue_style( 'onetone-customizer-jquery-ui', ONETONE_URI . 'assets/css/jquery-ui.min.css' ); 
  627. wp_enqueue_style( 'onetone-customizer-jquery-ui-theme', ONETONE_URI . 'assets/css/jquery-ui.theme.min.css' ); 
  628.  
  629. /** 
  630. * Sanitize and Print To Head 
  631. */ 
  632.  
  633. function onetone_customizer_print_css() {  
  634.  
  635. $onetone_options= array(); 
  636. $onetone_options= $this->onetone_get_customizer_data( $onetone_options ); 
  637. $style = ''; 
  638.  
  639. foreach ( $onetone_options as $data ) { 
  640.  
  641. $data = wp_parse_args( $data, self::$default_data ); 
  642.  
  643. $selectors = $data['selector']; 
  644. $newvalue = get_theme_mod( $data['slug'] ); 
  645.  
  646. if ( isset( $newvalue ) && ! empty( $newvalue ) ) { 
  647. switch ( $data['type'] ) { 
  648.  
  649. case 'color': 
  650. if ( true == $data['output'] ) { 
  651. $style .=  
  652. $selectors. '{' 
  653. .$data['property'].':'.$newvalue.' '.$data['property2'].'}'; 
  654. break; 
  655.  
  656. case 'color_rgb': 
  657. if ( true == $data['output'] ) { 
  658. $get_rgb_color = $this->onetone_hex2RGB( $newvalue ); 
  659. $red = $get_rgb_color['r'];  
  660. $green = $get_rgb_color['g'];  
  661. $blue = $get_rgb_color['b']; 
  662. $property2 = $data['property2'];  
  663. $rgb_color = 'rgb('.$red.', '.$green.', '.$blue.', ' . $property2 . ')'; 
  664.  
  665. $style .=  
  666. $selectors. '{' 
  667. .$data['property'].':'.$rgb_color.'}'; 
  668. break; 
  669.  
  670. case 'images': 
  671. if ( true == $data['output'] ) { 
  672. $style .= $selectors. '{'  
  673. .$data['property'].':url("'.$newvalue.'") '.' '.$data['property2'].'}'; 
  674. break; 
  675.  
  676. case 'google_font': 
  677. $style .= $selectors.'{'  
  678. .$data['property'].':'.$newvalue.' '.$data['property2'].'}'; 
  679. break; 
  680.  
  681. default: 
  682. break; 
  683. $style = "\n".'<style type="text/css">'.trim( $style ).'</style>'."\n"; 
  684. printf( '%s', $style ); 
  685.  
  686. /** 
  687. * Enqueue Google Font Base on Customizer Data 
  688. * @return void 
  689. **/ 
  690. function onetone_customizer_font_output() { 
  691.  
  692. $onetone_options = array(); 
  693. $onetone_data = $this->onetone_get_customizer_data( $onetone_options ); 
  694. $loaded_font = ''; 
  695.  
  696. foreach ( $onetone_data as $data ) { 
  697.  
  698. $data = wp_parse_args( $data, self::$default_data ); 
  699.  
  700. $selectors = $data['selector']; 
  701. $newvalue = get_theme_mod( $data['slug'] ); 
  702.  
  703. if ( $data['type'] == 'select_font' ) { 
  704. if ( isset( $newvalue ) && ! empty( $newvalue ) ) { 
  705. $get_selected_font = str_replace(' ', '+', $newvalue ); 
  706. $loaded_font .= '@import url(//fonts.googleapis.com/css?family='.$get_selected_font.');'; 
  707. }  
  708. $loaded_font = "\n".'<style type="text/css">'.trim( $loaded_font ).'</style>'."\n"; 
  709. printf( '%s', $loaded_font ); 
  710.  
  711. /** 
  712. * Convert Hexa to RGB 
  713. * @return void 
  714. **/ 
  715. function onetone_hex2RGB( $hex ) { 
  716. preg_match( "/^#{0, 1}([0-9a-f]{1, 6})$/i", $hex, $match ); 
  717.  
  718. if ( ! isset( $match[1] ) ) { 
  719. return false; 
  720.  
  721. if ( strlen( $match[1] ) == 6 ) { 
  722. list( $r, $g, $b ) = array( $hex[0] . $hex[1], $hex[2] . $hex[3], $hex[4] . $hex[5] ); 
  723. } elseif ( strlen( $match[1] ) == 3 ) { 
  724. list( $r, $g, $b ) = array( $hex[0] . $hex[0], $hex[1] . $hex[1], $hex[2] . $hex[2] ); 
  725. } else if ( strlen( $match[1] ) == 2 ) { 
  726. list( $r, $g, $b ) = array( $hex[0] . $hex[1], $hex[0] . $hex[1], $hex[0] . $hex[1] ); 
  727. } else if ( strlen( $match[1] ) == 1 ) { 
  728. list( $r, $g, $b ) = array( $hex . $hex, $hex . $hex, $hex . $hex ); 
  729. } else { 
  730. return false; 
  731.  
  732. $color = array(); 
  733. $color['r'] = hexdec( $r ); 
  734. $color['g'] = hexdec( $g ); 
  735. $color['b'] = hexdec( $b ); 
  736.  
  737. return $color; 
  738.