/includes/class-wcqc-settings.php

  1. <?php 
  2.  
  3. /** 
  4. * Settings class 
  5. */ 
  6. if ( ! class_exists( 'WooCommerce_Qinvoice_Connect_Settings' ) ) { 
  7.  
  8. class WooCommerce_Qinvoice_Connect_Settings { 
  9.  
  10. public $options_page_hook; 
  11. public $general_settings; 
  12. public $template_settings; 
  13. public $tab_name; 
  14.  
  15. public function __construct() { 
  16. add_action( 'admin_menu', array( &$this, 'settings' ) ); // Add menu. 
  17. add_action( 'admin_init', array( &$this, 'init_settings' ) ); // Registers settings 
  18.  
  19. // Add links to WordPress plugins page 
  20. add_filter( 'plugin_action_links_'.WooCommerce_Qinvoice_Connect::$plugin_basename, array( &$this, 'wcqc_add_settings_link' ) ); 
  21. add_filter( 'plugin_row_meta', array( $this, 'add_support_links' ), 10, 2 ); 
  22.  
  23. $this->general_settings = get_option('wcqc_general_settings'); 
  24. $this->tab_name = 'woocommerce-qinvoice-connect'; 
  25.  
  26. $options = get_option( 'wcqc_general_settings' ); 
  27. if(!isset($options['webshop_secret']) || $options['webshop_secret'] == '') { 
  28. $options['webshop_secret'] = md5(rand(0, 999999)); 
  29. update_option( 'wcqc_general_settings', $options); 
  30.  
  31. public function settings() { 
  32. $parent_slug = 'woocommerce'; 
  33.  
  34. $this->options_page_hook = add_submenu_page( 
  35. $parent_slug,  
  36. __( 'Q-invoice connect', 'woocommerce-qinvoice-connect' ),  
  37. __( 'Q-invoice connect', 'woocommerce-qinvoice-connect' ),  
  38. 'manage_options',  
  39. 'wcqc_options_page',  
  40. array( $this, 'settings_page' ) 
  41. ); 
  42.  
  43.  
  44. /** 
  45. * Add a tab to the settings page 
  46. */ 
  47. public function add_settings_tab($tabs) { 
  48. $tabs[$this->tab_name] = __( 'Q-invoice', 'woocommerce-qinvoice-connect' ); 
  49. return $tabs; 
  50.  
  51.  
  52. /** 
  53. * Add settings link to plugins page 
  54. */ 
  55. public function wcqc_add_settings_link( $links ) { 
  56. $settings_link = '<a href="admin.php?page=wcqc_options_page">'. __( 'Settings', 'woocommerce' ) . '</a>'; 
  57. array_push( $links, $settings_link ); 
  58. $signup_link = '<a href="https://app.q-invoice.com/signup.php" target="_blank" title="' . __( 'Create an account', 'woocommerce-qinvoice-connect' ) . '">' . __( 'Create an account', 'woocommerce-qinvoice-connect' ) . '</a>'; 
  59. array_push( $links, $signup_link ); 
  60. return $links; 
  61.  
  62. /** 
  63. * Add various support links to plugin page 
  64. * after meta (version, authors, site) 
  65. */ 
  66. public function add_support_links( $links, $file ) { 
  67. if ( !current_user_can( 'install_plugins' ) ) { 
  68. return $links; 
  69.  
  70. if ( $file == WooCommerce_Qinvoice_Connect::$plugin_basename ) { 
  71. $links[] = '<a href="mailto:support@q-invoice.com" target="_blank" title="' . __( 'Get support', 'woocommerce-qinvoice-connect' ) . '">' . __( 'Get support', 'woocommerce-qinvoice-connect' ) . '</a>'; 
  72. return $links; 
  73.  
  74. public function settings_page() { 
  75.  
  76.  
  77. $active_tab = 'general'; 
  78. ?> 
  79.  
  80. <div class="wrap"> 
  81. <div class="icon32" id="icon-options-general"><br /></div> 
  82. <h2><?php _e( 'WooCommerce q-invoice connect', 'woocommerce-qinvoice-connect' ); ?></h2> 
  83. <form method="post" action="options.php"> 
  84. <?php 
  85. settings_fields( 'wcqc_'.$active_tab.'_settings' ); 
  86. do_settings_sections( 'wcqc_'.$active_tab.'_settings' ); 
  87.  
  88. submit_button(); 
  89. ?> 
  90.  
  91. </form> 
  92. <?php 
  93. do_action( 'wcqc_after_settings_page', $active_tab ); ?> 
  94. </div> 
  95. <?php 
  96.  
  97.  
  98. /** 
  99. * User settings. 
  100. *  
  101. */ 
  102.  
  103. public function init_settings() { 
  104. global $woocommerce; 
  105.  
  106. /**************************************/ 
  107. /*********** GENERAL SETTINGS *********/ 
  108. /**************************************/ 
  109.  
  110. $option = 'wcqc_general_settings'; 
  111.  
  112. // Create option in wp_options. 
  113. if ( false == get_option( $option ) ) { 
  114. add_option( $option ); 
  115.  
  116.  
  117.  
  118. // Section. 
  119. add_settings_section( 
  120. 'general_settings',  
  121. __( 'General settings', 'woocommerce-qinvoice-connect' ),  
  122. array( &$this, 'section_options_callback' ),  
  123. $option 
  124. ); 
  125.  
  126. add_settings_field( 
  127. 'api_url',  
  128. __( 'API url', 'woocommerce-qinvoice-connect' ),  
  129. array( &$this, 'text_element_callback' ),  
  130. $option,  
  131. 'general_settings',  
  132. array( 
  133. 'menu' => $option,  
  134. 'id' => 'api_url',  
  135. 'size' => '72',  
  136. 'description' => sprintf(__( 'eg. %s', 'woocommerce-qinvoice-connect' ), 'https://app.q-invoice.com/api/xml/1.1/') 
  137. ); 
  138.  
  139. add_settings_field( 
  140. 'api_username',  
  141. __( 'API username', 'woocommerce-qinvoice-connect' ),  
  142. array( &$this, 'text_element_callback' ),  
  143. $option,  
  144. 'general_settings',  
  145. array( 
  146. 'menu' => $option,  
  147. 'id' => 'api_username',  
  148. 'size' => '25',  
  149. 'description' => __( 'Your API username', 'woocommerce-qinvoice-connect' ) 
  150. ); 
  151.  
  152. add_settings_field( 
  153. 'api_password',  
  154. __( 'API password', 'woocommerce-qinvoice-connect' ),  
  155. array( &$this, 'text_element_callback' ),  
  156. $option,  
  157. 'general_settings',  
  158. array( 
  159. 'menu' => $option,  
  160. 'id' => 'api_password',  
  161. 'size' => '25',  
  162. 'description' => __( 'Your API password', 'woocommerce-qinvoice-connect' ) 
  163. ); 
  164.  
  165. add_settings_field( 
  166. 'request_type',  
  167. __( 'Document type', 'woocommerce-qinvoice-connect' ),  
  168. array( &$this, 'select_element_callback' ),  
  169. $option,  
  170. 'general_settings',  
  171. array( 
  172. 'menu' => $option,  
  173. 'id' => 'request_type',  
  174. 'size' => '25',  
  175. 'description' => __( 'Set the document type here', 'woocommerce-qinvoice-connect' ),  
  176. 'options' => array(  
  177. 'invoice' => __('Invoice', 'woocommerce-qinvoice-connect'),  
  178. 'quote' => __('Quote', 'woocommerce-qinvoice-connect'),  
  179. 'orderconfirmation' => __('Order confirmation', 'woocommerce-qinvoice-connect'),  
  180. 'proforma' => __('Proforma invoice', 'woocommerce-qinvoice-connect'),  
  181. 'recurring.monthly' => __('Recurring (monthly)', 'woocommerce-qinvoice-connect'),  
  182. 'recurring.quarterly' => __('Recurring (quarterly)', 'woocommerce-qinvoice-connect'),  
  183. 'recurring.yearly' => __('Recurring (yearly)', 'woocommerce-qinvoice-connect') 
  184. ); 
  185.  
  186. if(defined('WCML_VERSION') && 1==1) { 
  187. // WCML is active 
  188. global $woocommerce_wpml; 
  189.  
  190. $settings = $woocommerce_wpml->get_settings(); 
  191.  
  192. foreach($settings['currency_options'] as $currency => $c_options) { 
  193. add_settings_field( 
  194. 'layout_code_'. $currency,  
  195. sprintf(__( 'Layout code for %s', 'woocommerce-qinvoice-connect' ), $currency),  
  196. array( &$this, 'text_element_callback' ),  
  197. $option,  
  198. 'general_settings',  
  199. array( 
  200. 'menu' => $option,  
  201. 'id' => 'layout_code_'. $currency,  
  202. 'size' => '25',  
  203. 'description' => sprintf(__('Your q-invoice layout code for currency: %s', 'woocommerce-qinvoice-connect' ), $currency) 
  204. ); 
  205.  
  206.  
  207. }else{ 
  208.  
  209. add_settings_field( 
  210. 'layout_code',  
  211. __( 'Layout code', 'woocommerce-qinvoice-connect' ),  
  212. array( &$this, 'text_element_callback' ),  
  213. $option,  
  214. 'general_settings',  
  215. array( 
  216. 'menu' => $option,  
  217. 'id' => 'layout_code',  
  218. 'size' => '25',  
  219. 'description' => __( 'Your q-invoice layout code', 'woocommerce-qinvoice-connect' ) 
  220. ); 
  221.  
  222. add_settings_field( 
  223. 'invoice_remark',  
  224. __( 'Document remark', 'woocommerce-qinvoice-connect' ),  
  225. array( &$this, 'text_element_callback' ),  
  226. $option,  
  227. 'general_settings',  
  228. array( 
  229. 'menu' => $option,  
  230. 'id' => 'invoice_remark',  
  231. 'size' => '40',  
  232. 'description' => __( 'eg. Your order: {order_id}. Your payment method: {method}. (you can also use {order_number} and {order_date}). Use {customer_note} for the customer note', 'woocommerce-qinvoice-connect' ) 
  233. ); 
  234.  
  235. add_settings_field( 
  236. 'paid_remark',  
  237. __( 'Paid remark', 'woocommerce-qinvoice-connect' ),  
  238. array( &$this, 'text_element_callback' ),  
  239. $option,  
  240. 'general_settings',  
  241. array( 
  242. 'menu' => $option,  
  243. 'id' => 'paid_remark',  
  244. 'size' => '40',  
  245. 'description' => __( 'eg. Your payment has been received. Via {method}', 'woocommerce-qinvoice-connect' ) 
  246. ); 
  247.  
  248. add_settings_field( 
  249. 'invoice_reference',  
  250. __( 'Document reference', 'woocommerce-qinvoice-connect' ),  
  251. array( &$this, 'text_element_callback' ),  
  252. $option,  
  253. 'general_settings',  
  254. array( 
  255. 'menu' => $option,  
  256. 'id' => 'invoice_reference',  
  257. 'size' => '25',  
  258. 'description' => __( 'eg. The order number ({order_number})', 'woocommerce-qinvoice-connect' ) 
  259. ); 
  260.  
  261. add_settings_field( 
  262. 'invoice_tag',  
  263. __( 'Document tag', 'woocommerce-qinvoice-connect' ),  
  264. array( &$this, 'text_element_callback' ),  
  265. $option,  
  266. 'general_settings',  
  267. array( 
  268. 'menu' => $option,  
  269. 'id' => 'invoice_tag',  
  270. 'size' => '25',  
  271. 'description' => __( 'eg. Your webshop name (also accepted: {order_number}, {method} and {order_date}', 'woocommerce-qinvoice-connect' ) 
  272. ); 
  273.  
  274. add_settings_field( 
  275. 'invoice_trigger',  
  276. __( 'Send request on:', 'woocommerce-qinvoice-connect' ),  
  277. array( &$this, 'radio_element_callback' ),  
  278. $option,  
  279. 'general_settings',  
  280. array( 
  281. 'menu' => $option,  
  282. 'id' => 'invoice_trigger',  
  283. 'options' => array( 
  284. 'order' => __('Every new order', 'woocommerce-qinvoice-connect'),  
  285. 'payment' => __( 'After each succesfull payment' , 'woocommerce-qinvoice-connect' ),  
  286. 'completed' => __( 'When order is marked completed' , 'woocommerce-qinvoice-connect' ),  
  287. 'none' => __( 'Disable automatic invoicing' , 'woocommerce-qinvoice-connect' ) 
  288. ),  
  289. 'description' => __('When to send invoice/quote request to q-invoice?', 'woocommerce-qinvoice-connect'),  
  290. ); 
  291.  
  292. add_settings_field( 
  293. 'invoice_action',  
  294. __( 'After request:', 'woocommerce-qinvoice-connect' ),  
  295. array( &$this, 'radio_element_callback' ),  
  296. $option,  
  297. 'general_settings',  
  298. array( 
  299. 'menu' => $option,  
  300. 'id' => 'invoice_action',  
  301. 'options' => array( 
  302. '0' => __('Save document as draft', 'woocommerce-qinvoice-connect'),  
  303. '1' => __( 'Finalize and save PDF' , 'woocommerce-qinvoice-connect' ),  
  304. '2' => __( 'Finalize and send email with PDF attached to customer' , 'woocommerce-qinvoice-connect' ) 
  305. ),  
  306. 'description' => __('What to do after request has been sent?', 'woocommerce-qinvoice-connect'),  
  307. ); 
  308.  
  309. add_settings_field( 
  310. 'save_relation',  
  311. __( 'Save relation:', 'woocommerce-qinvoice-connect' ),  
  312. array( &$this, 'radio_element_callback' ),  
  313. $option,  
  314. 'general_settings',  
  315. array( 
  316. 'menu' => $option,  
  317. 'id' => 'save_relation',  
  318. 'options' => array( 
  319. '0' => __('No', 'woocommerce-qinvoice-connect'),  
  320. '1' => __( 'Yes' , 'woocommerce-qinvoice-connect' ) 
  321. ),  
  322. 'description' => __('Automatically save or update relation details?', 'woocommerce-qinvoice-connect'),  
  323. ); 
  324.  
  325. add_settings_field( 
  326. 'add_item_meta',  
  327. __( 'Add item meta:', 'woocommerce-qinvoice-connect' ),  
  328. array( &$this, 'radio_element_callback' ),  
  329. $option,  
  330. 'general_settings',  
  331. array( 
  332. 'menu' => $option,  
  333. 'id' => 'add_item_meta',  
  334. 'options' => array( 
  335. '0' => __('No', 'woocommerce-qinvoice-connect'),  
  336. '1' => __( 'Yes' , 'woocommerce-qinvoice-connect' ) 
  337. ),  
  338. 'description' => __('Some plugins add meta data to order items. To display this info on the invoice select \'Yes\'.', 'woocommerce-qinvoice-connect'),  
  339. ); 
  340.  
  341.  
  342. add_settings_field( 
  343. 'coupon_vat',  
  344. __( 'Coupon vat', 'woocommerce-qinvoice-connect' ),  
  345. array( &$this, 'text_element_callback' ),  
  346. $option,  
  347. 'general_settings',  
  348. array( 
  349. 'menu' => $option,  
  350. 'id' => 'coupon_vat',  
  351. 'size' => '5',  
  352. 'description' => __( 'eg. 21 (without %)', 'woocommerce-qinvoice-connect' ) 
  353. ); 
  354.  
  355. add_settings_field( 
  356. 'default_ledger_account',  
  357. __( 'Default ledger account', 'woocommerce-qinvoice-connect' ),  
  358. array( &$this, 'text_element_callback' ),  
  359. $option,  
  360. 'general_settings',  
  361. array( 
  362. 'menu' => $option,  
  363. 'id' => 'default_ledger_account',  
  364. 'size' => '10',  
  365. 'description' => __( 'The default ledger account for your revenue. eg. 8000', 'woocommerce-qinvoice-connect' ) 
  366. ); 
  367.  
  368.  
  369.  
  370. add_settings_field( 
  371. 'calculation_method',  
  372. __( 'Calculation method:', 'woocommerce-qinvoice-connect' ),  
  373. array( &$this, 'radio_element_callback' ),  
  374. $option,  
  375. 'general_settings',  
  376. array( 
  377. 'menu' => $option,  
  378. 'id' => 'calculation_method',  
  379. 'options' => array( 
  380. 'incl' => __('Prices <strong>including VAT</strong> are leading', 'woocommerce-qinvoice-connect'),  
  381. 'excl' => __( 'Prices <strong>excluding VAT</strong> are leading' , 'woocommerce-qinvoice-connect' ) 
  382. ),  
  383. 'description' => __('Set the preferred calculation method', 'woocommerce-qinvoice-connect'),  
  384. ); 
  385.  
  386. add_settings_field( 
  387. 'invoice_date',  
  388. __( 'Invoice date:', 'woocommerce-qinvoice-connect' ),  
  389. array( &$this, 'radio_element_callback' ),  
  390. $option,  
  391. 'general_settings',  
  392. array( 
  393. 'menu' => $option,  
  394. 'id' => 'invoice_date',  
  395. 'options' => array( 
  396. 'order' => __('Use order date for invoice date', 'woocommerce-qinvoice-connect'),  
  397. 'invoice' => __( 'Use date of sending request' , 'woocommerce-qinvoice-connect' ) 
  398. ),  
  399. 'description' => __('Which date should be used as invoice date?', 'woocommerce-qinvoice-connect'),  
  400. ); 
  401.  
  402.  
  403. $available_gateways = get_option('woocommerce_gateway_order'); 
  404. //print_r($available_gateways); 
  405.  
  406. if ( $available_gateways ) { 
  407.  
  408. foreach ( $available_gateways as $gateway => $v ) { 
  409. $options_array[$gateway] = $gateway;  
  410. add_settings_field( 
  411. 'exclude_payment_method',  
  412. __( 'Exclude payment methods:', 'woocommerce-qinvoice-connect' ),  
  413. array( &$this, 'multiple_checkbox_element_callback' ),  
  414. $option,  
  415. 'general_settings',  
  416. array( 
  417. 'menu' => $option,  
  418. 'id' => 'exclude_payment_method',  
  419. 'options' => $options_array,  
  420. 'description' => __('Exclude certain payment methods. For selected methods no request will be sent.', 'woocommerce-qinvoice-connect'),  
  421. ); 
  422. }  
  423.  
  424.  
  425. add_settings_field( 
  426. 'webshop_secret',  
  427. __( 'Webshop secret', 'woocommerce-qinvoice-connect' ),  
  428. array( &$this, 'text_element_callback' ),  
  429. $option,  
  430. 'general_settings',  
  431. array( 
  432. 'menu' => $option,  
  433. 'id' => 'webshop_secret',  
  434. 'size' => '35',  
  435. 'description' => __( 'This webshops\' secret key', 'woocommerce-qinvoice-connect' ),  
  436. 'disabled' => 'disabled' 
  437. ); 
  438.  
  439. // Register settings. 
  440. register_setting( $option, $option, array( &$this, 'validate_options' ) ); 
  441.  
  442.  
  443. /** 
  444. * Set default settings. 
  445. */ 
  446. public function default_settings() { 
  447. global $wcqc; 
  448.  
  449. $default_general = array( 
  450. 'api_url' => 'https://app.q-invoice.com/api/xml/1.1/',  
  451. ); 
  452.  
  453. update_option( 'wcqc_general_settings', $default_general ); 
  454.  
  455. // Text element callback. 
  456. public function text_element_callback( $args ) { 
  457. $menu = $args['menu']; 
  458. $id = $args['id']; 
  459. $size = isset( $args['size'] ) ? $args['size'] : '25'; 
  460. $disabled = isset( $args['disabled'] ) ? "disabled='". $args['disabled'] ."'" : ""; 
  461.  
  462. $options = get_option( $menu ); 
  463.  
  464. if ( isset( $options[$id] ) ) { 
  465. $current = $options[$id]; 
  466. } else { 
  467. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  468.  
  469. $html = sprintf( '<input type="text" id="%1$s" name="%2$s[%1$s]" value="%3$s" size="%4$s" %5$s/>', $id, $menu, $current, $size, $disabled ); 
  470.  
  471. // Displays option description. 
  472. if ( isset( $args['description'] ) ) { 
  473. $html .= sprintf( '<span class="description">%s</span>', $args['description'] ); 
  474.  
  475. echo $html; 
  476.  
  477. // Text element callback. 
  478. public function textarea_element_callback( $args ) { 
  479. $menu = $args['menu']; 
  480. $id = $args['id']; 
  481. $width = $args['width']; 
  482. $height = $args['height']; 
  483.  
  484. $options = get_option( $menu ); 
  485.  
  486. if ( isset( $options[$id] ) ) { 
  487. $current = $options[$id]; 
  488. } else { 
  489. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  490.  
  491. $html = sprintf( '<textarea id="%1$s" name="%2$s[%1$s]" cols="%4$s" rows="%5$s"/>%3$s</textarea>', $id, $menu, $current, $width, $height ); 
  492.  
  493. // Displays option description. 
  494. if ( isset( $args['description'] ) ) { 
  495. $html .= sprintf( '<p class="description">%s</p>', $args['description'] ); 
  496.  
  497. echo $html; 
  498.  
  499.  
  500. /** 
  501. * Checkbox field callback. 
  502. * 
  503. * @param array $args Field arguments. 
  504. * 
  505. * @return string Checkbox field. 
  506. */ 
  507. public function checkbox_element_callback( $args ) { 
  508. $menu = $args['menu']; 
  509. $id = $args['id']; 
  510.  
  511. $options = get_option( $menu ); 
  512.  
  513. if ( isset( $options[$id] ) ) { 
  514. $current = $options[$id]; 
  515. } else { 
  516. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  517.  
  518. $html = sprintf( '<input type="checkbox" id="%1$s" name="%2$s[%1$s]" value="1"%3$s />', $id, $menu, checked( 1, $current, false ) ); 
  519.  
  520. // Displays option description. 
  521. if ( isset( $args['description'] ) ) { 
  522. $html .= sprintf( '<p class="description">%s</p>', $args['description'] ); 
  523.  
  524. echo $html; 
  525.  
  526. /** 
  527. * Multiple Checkbox field callback. 
  528. * 
  529. * @param array $args Field arguments. 
  530. * 
  531. * @return string Checkbox field. 
  532. */ 
  533. public function multiple_checkbox_element_callback( $args ) { 
  534. $menu = $args['menu']; 
  535. $id = $args['id']; 
  536.  
  537. $options = get_option( $menu ); 
  538.  
  539.  
  540. foreach ( $args['options'] as $key => $label ) { 
  541. $current = ( isset( $options[$id][$key] ) ) ? $options[$id][$key] : ''; 
  542. printf( '<input type="checkbox" id="%1$s[%2$s][%3$s]" name="%1$s[%2$s][%3$s]" value="1"%4$s /> %5$s<br/>', $menu, $id, $key, checked( 1, $current, false ), $label ); 
  543.  
  544. // Displays option description. 
  545. if ( isset( $args['description'] ) ) { 
  546. printf( '<p class="description">%s</p>', $args['description'] ); 
  547.  
  548. /** 
  549. * Select element callback. 
  550. * 
  551. * @param array $args Field arguments. 
  552. * 
  553. * @return string Select field. 
  554. */ 
  555. public function select_element_callback( $args ) { 
  556. $menu = $args['menu']; 
  557. $id = $args['id']; 
  558.  
  559. $options = get_option( $menu ); 
  560.  
  561. if ( isset( $options[$id] ) ) { 
  562. $current = $options[$id]; 
  563. } else { 
  564. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  565.  
  566. $html = sprintf( '<select id="%1$s" name="%2$s[%1$s]">', $id, $menu ); 
  567.  
  568. foreach ( $args['options'] as $key => $label ) { 
  569. $html .= sprintf( '<option value="%s"%s>%s</option>', $key, selected( $current, $key, false ), $label ); 
  570.  
  571. $html .= '</select>'; 
  572.  
  573. // Displays option description. 
  574. if ( isset( $args['description'] ) ) { 
  575. $html .= sprintf( '<p class="description">%s</p>', $args['description'] ); 
  576.  
  577. echo $html; 
  578.  
  579. /** 
  580. * Displays a radio settings field 
  581. * 
  582. * @param array $args settings field args 
  583. */ 
  584. public function radio_element_callback( $args ) { 
  585. $menu = $args['menu']; 
  586. $id = $args['id']; 
  587.  
  588. $options = get_option( $menu ); 
  589.  
  590. if ( isset( $options[$id] ) ) { 
  591. $current = $options[$id]; 
  592. } else { 
  593. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  594.  
  595. $html = ''; 
  596. foreach ( $args['options'] as $key => $label ) { 
  597. $html .= sprintf( '<input type="radio" class="radio" id="%1$s[%2$s][%3$s]" name="%1$s[%2$s]" value="%3$s"%4$s />', $menu, $id, $key, checked( $current, $key, false ) ); 
  598. $html .= sprintf( '<label for="%1$s[%2$s][%3$s]"> %4$s</label><br>', $menu, $id, $key, $label); 
  599.  
  600. // Displays option description. 
  601. if ( isset( $args['description'] ) ) { 
  602. $html .= sprintf( '<p class="description">%s</p>', $args['description'] ); 
  603.  
  604. echo $html; 
  605.  
  606.  
  607. /** 
  608. * Section null callback. 
  609. * 
  610. * @return void. 
  611. */ 
  612. public function section_options_callback() { 
  613.  
  614. /** 
  615. * Section null callback. 
  616. * 
  617. * @return void. 
  618. */ 
  619. public function custom_fields_section() { 
  620. $menu = $args['menu']; 
  621. $id = $args['id']; 
  622. $size = isset( $args['size'] ) ? $args['size'] : '25'; 
  623.  
  624. $options = get_option( $menu ); 
  625.  
  626. if ( isset( $options[$id] ) ) { 
  627. $current = $options[$id]; 
  628. } else { 
  629. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  630.  
  631. $html = sprintf( '<code>%1$s</code>', $current); 
  632.  
  633. // Displays option description. 
  634. if ( isset( $args['description'] ) ) { 
  635. $html .= sprintf( '<span class="description">%s</span>', $args['description'] ); 
  636.  
  637. echo $html; 
  638.  
  639. /** 
  640. * Validate options. 
  641. * 
  642. * @param array $input options to valid. 
  643. * 
  644. * @return array validated options. 
  645. */ 
  646. public function validate_options( $input ) { 
  647. // Create our array for storing the validated options. 
  648. $output = array(); 
  649.  
  650. // Loop through each of the incoming options. 
  651. foreach ( $input as $key => $value ) { 
  652.  
  653. // Check to see if the current option has a value. If so, process it. 
  654. if ( isset( $input[$key] ) ) { 
  655. // Strip all HTML and PHP tags and properly handle quoted strings. 
  656. if ( is_array( $input[$key] ) ) { 
  657. foreach ( $input[$key] as $sub_key => $sub_value ) { 
  658. $output[$key][$sub_key] = strip_tags( $input[$key][$sub_key] ); 
  659.  
  660. } else { 
  661. $output[$key] = strip_tags( $input[$key] ); 
  662.  
  663. // Return the array processing any additional functions filtered by this action. 
  664. return apply_filters( 'wcqc_validate_input', $output, $input ); 
  665.  
  666.  
  667.  
  668. } // end class WooCommerce_Qinvoice_Connect_Settings 
  669.  
  670. } // end class_exists 
.