/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. 'send_payment_status',  
  294. __( 'Send payment status:', 'woocommerce-qinvoice-connect' ),  
  295. array( &$this, 'radio_element_callback' ),  
  296. $option,  
  297. 'general_settings',  
  298. array( 
  299. 'menu' => $option,  
  300. 'id' => 'send_payment_status',  
  301. 'options' => array( 
  302. 'yes' => __('Yes', 'woocommerce-qinvoice-connect'),  
  303. 'no' => __( 'No, I will update payment status myself' , 'woocommerce-qinvoice-connect' ) 
  304.  
  305. ),  
  306. 'description' => __('If order is paid, copy this payment to the invoice or not. Only works with trigger "succesfull payment".', 'woocommerce-qinvoice-connect'),  
  307. ); 
  308.  
  309. add_settings_field( 
  310. 'invoice_action',  
  311. __( 'After request:', 'woocommerce-qinvoice-connect' ),  
  312. array( &$this, 'radio_element_callback' ),  
  313. $option,  
  314. 'general_settings',  
  315. array( 
  316. 'menu' => $option,  
  317. 'id' => 'invoice_action',  
  318. 'options' => array( 
  319. '0' => __('Save document as draft', 'woocommerce-qinvoice-connect'),  
  320. '1' => __( 'Finalize and save PDF' , 'woocommerce-qinvoice-connect' ),  
  321. '2' => __( 'Finalize and send email with PDF attached to customer' , 'woocommerce-qinvoice-connect' ) 
  322. ),  
  323. 'description' => __('What to do after request has been sent?', 'woocommerce-qinvoice-connect'),  
  324. ); 
  325.  
  326. add_settings_field( 
  327. 'save_relation',  
  328. __( 'Save relation:', 'woocommerce-qinvoice-connect' ),  
  329. array( &$this, 'radio_element_callback' ),  
  330. $option,  
  331. 'general_settings',  
  332. array( 
  333. 'menu' => $option,  
  334. 'id' => 'save_relation',  
  335. 'options' => array( 
  336. '0' => __('No', 'woocommerce-qinvoice-connect'),  
  337. '1' => __( 'Yes' , 'woocommerce-qinvoice-connect' ) 
  338. ),  
  339. 'description' => __('Automatically save or update relation details?', 'woocommerce-qinvoice-connect'),  
  340. ); 
  341.  
  342. add_settings_field( 
  343. 'add_item_meta',  
  344. __( 'Add item meta:', 'woocommerce-qinvoice-connect' ),  
  345. array( &$this, 'radio_element_callback' ),  
  346. $option,  
  347. 'general_settings',  
  348. array( 
  349. 'menu' => $option,  
  350. 'id' => 'add_item_meta',  
  351. 'options' => array( 
  352. '0' => __('No', 'woocommerce-qinvoice-connect'),  
  353. '1' => __( 'Yes' , 'woocommerce-qinvoice-connect' ) 
  354. ),  
  355. 'description' => __('Some plugins add meta data to order items. To display this info on the invoice select \'Yes\'.', 'woocommerce-qinvoice-connect'),  
  356. ); 
  357.  
  358.  
  359. add_settings_field( 
  360. 'coupon_vat',  
  361. __( 'Coupon vat', 'woocommerce-qinvoice-connect' ),  
  362. array( &$this, 'text_element_callback' ),  
  363. $option,  
  364. 'general_settings',  
  365. array( 
  366. 'menu' => $option,  
  367. 'id' => 'coupon_vat',  
  368. 'size' => '5',  
  369. 'description' => __( 'eg. 21 (without %)', 'woocommerce-qinvoice-connect' ) 
  370. ); 
  371.  
  372. add_settings_field( 
  373. 'default_ledger_account',  
  374. __( 'Default ledger account', 'woocommerce-qinvoice-connect' ),  
  375. array( &$this, 'text_element_callback' ),  
  376. $option,  
  377. 'general_settings',  
  378. array( 
  379. 'menu' => $option,  
  380. 'id' => 'default_ledger_account',  
  381. 'size' => '10',  
  382. 'description' => __( 'The default ledger account for your revenue. eg. 8000', 'woocommerce-qinvoice-connect' ) 
  383. ); 
  384.  
  385.  
  386.  
  387. add_settings_field( 
  388. 'calculation_method',  
  389. __( 'Calculation method:', 'woocommerce-qinvoice-connect' ),  
  390. array( &$this, 'radio_element_callback' ),  
  391. $option,  
  392. 'general_settings',  
  393. array( 
  394. 'menu' => $option,  
  395. 'id' => 'calculation_method',  
  396. 'options' => array( 
  397. 'incl' => __('Prices <strong>including VAT</strong> are leading', 'woocommerce-qinvoice-connect'),  
  398. 'excl' => __( 'Prices <strong>excluding VAT</strong> are leading' , 'woocommerce-qinvoice-connect' ) 
  399. ),  
  400. 'description' => __('Set the preferred calculation method', 'woocommerce-qinvoice-connect'),  
  401. ); 
  402.  
  403. add_settings_field( 
  404. 'invoice_date',  
  405. __( 'Invoice date:', 'woocommerce-qinvoice-connect' ),  
  406. array( &$this, 'radio_element_callback' ),  
  407. $option,  
  408. 'general_settings',  
  409. array( 
  410. 'menu' => $option,  
  411. 'id' => 'invoice_date',  
  412. 'options' => array( 
  413. 'order' => __('Use order date for invoice date', 'woocommerce-qinvoice-connect'),  
  414. 'invoice' => __( 'Use date of sending request' , 'woocommerce-qinvoice-connect' ) 
  415. ),  
  416. 'description' => __('Which date should be used as invoice date?', 'woocommerce-qinvoice-connect'),  
  417. ); 
  418.  
  419.  
  420. $available_gateways = get_option('woocommerce_gateway_order'); 
  421. //print_r($available_gateways); 
  422.  
  423. if ( $available_gateways ) { 
  424.  
  425. foreach ( $available_gateways as $gateway => $v ) { 
  426. $options_array[$gateway] = $gateway;  
  427. add_settings_field( 
  428. 'exclude_payment_method',  
  429. __( 'Exclude payment methods:', 'woocommerce-qinvoice-connect' ),  
  430. array( &$this, 'multiple_checkbox_element_callback' ),  
  431. $option,  
  432. 'general_settings',  
  433. array( 
  434. 'menu' => $option,  
  435. 'id' => 'exclude_payment_method',  
  436. 'options' => $options_array,  
  437. 'description' => __('Exclude certain payment methods. For selected methods no request will be sent.', 'woocommerce-qinvoice-connect'),  
  438. ); 
  439. }  
  440.  
  441.  
  442. add_settings_field( 
  443. 'webshop_secret',  
  444. __( 'Webshop secret', 'woocommerce-qinvoice-connect' ),  
  445. array( &$this, 'text_element_callback' ),  
  446. $option,  
  447. 'general_settings',  
  448. array( 
  449. 'menu' => $option,  
  450. 'id' => 'webshop_secret',  
  451. 'size' => '35',  
  452. 'description' => __( 'This webshops\' secret key', 'woocommerce-qinvoice-connect' ),  
  453. 'disabled' => 'disabled' 
  454. ); 
  455.  
  456. // Register settings. 
  457. register_setting( $option, $option, array( &$this, 'validate_options' ) ); 
  458.  
  459.  
  460. /** 
  461. * Set default settings. 
  462. */ 
  463. public function default_settings() { 
  464. global $wcqc; 
  465.  
  466. $default_general = array( 
  467. 'api_url' => 'https://app.q-invoice.com/api/xml/1.1/',  
  468. ); 
  469.  
  470. update_option( 'wcqc_general_settings', $default_general ); 
  471.  
  472. // Text element callback. 
  473. public function text_element_callback( $args ) { 
  474. $menu = $args['menu']; 
  475. $id = $args['id']; 
  476. $size = isset( $args['size'] ) ? $args['size'] : '25'; 
  477. $disabled = isset( $args['disabled'] ) ? "disabled='". $args['disabled'] ."'" : ""; 
  478.  
  479. $options = get_option( $menu ); 
  480.  
  481. if ( isset( $options[$id] ) ) { 
  482. $current = $options[$id]; 
  483. } else { 
  484. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  485.  
  486. $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 ); 
  487.  
  488. // Displays option description. 
  489. if ( isset( $args['description'] ) ) { 
  490. $html .= sprintf( '<span class="description">%s</span>', $args['description'] ); 
  491.  
  492. echo $html; 
  493.  
  494. // Text element callback. 
  495. public function textarea_element_callback( $args ) { 
  496. $menu = $args['menu']; 
  497. $id = $args['id']; 
  498. $width = $args['width']; 
  499. $height = $args['height']; 
  500.  
  501. $options = get_option( $menu ); 
  502.  
  503. if ( isset( $options[$id] ) ) { 
  504. $current = $options[$id]; 
  505. } else { 
  506. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  507.  
  508. $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 ); 
  509.  
  510. // Displays option description. 
  511. if ( isset( $args['description'] ) ) { 
  512. $html .= sprintf( '<p class="description">%s</p>', $args['description'] ); 
  513.  
  514. echo $html; 
  515.  
  516.  
  517. /** 
  518. * Checkbox field callback. 
  519. * 
  520. * @param array $args Field arguments. 
  521. * 
  522. * @return string Checkbox field. 
  523. */ 
  524. public function checkbox_element_callback( $args ) { 
  525. $menu = $args['menu']; 
  526. $id = $args['id']; 
  527.  
  528. $options = get_option( $menu ); 
  529.  
  530. if ( isset( $options[$id] ) ) { 
  531. $current = $options[$id]; 
  532. } else { 
  533. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  534.  
  535. $html = sprintf( '<input type="checkbox" id="%1$s" name="%2$s[%1$s]" value="1"%3$s />', $id, $menu, checked( 1, $current, false ) ); 
  536.  
  537. // Displays option description. 
  538. if ( isset( $args['description'] ) ) { 
  539. $html .= sprintf( '<p class="description">%s</p>', $args['description'] ); 
  540.  
  541. echo $html; 
  542.  
  543. /** 
  544. * Multiple Checkbox field callback. 
  545. * 
  546. * @param array $args Field arguments. 
  547. * 
  548. * @return string Checkbox field. 
  549. */ 
  550. public function multiple_checkbox_element_callback( $args ) { 
  551. $menu = $args['menu']; 
  552. $id = $args['id']; 
  553.  
  554. $options = get_option( $menu ); 
  555.  
  556.  
  557. foreach ( $args['options'] as $key => $label ) { 
  558. $current = ( isset( $options[$id][$key] ) ) ? $options[$id][$key] : ''; 
  559. 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 ); 
  560.  
  561. // Displays option description. 
  562. if ( isset( $args['description'] ) ) { 
  563. printf( '<p class="description">%s</p>', $args['description'] ); 
  564.  
  565. /** 
  566. * Select element callback. 
  567. * 
  568. * @param array $args Field arguments. 
  569. * 
  570. * @return string Select field. 
  571. */ 
  572. public function select_element_callback( $args ) { 
  573. $menu = $args['menu']; 
  574. $id = $args['id']; 
  575.  
  576. $options = get_option( $menu ); 
  577.  
  578. if ( isset( $options[$id] ) ) { 
  579. $current = $options[$id]; 
  580. } else { 
  581. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  582.  
  583. $html = sprintf( '<select id="%1$s" name="%2$s[%1$s]">', $id, $menu ); 
  584.  
  585. foreach ( $args['options'] as $key => $label ) { 
  586. $html .= sprintf( '<option value="%s"%s>%s</option>', $key, selected( $current, $key, false ), $label ); 
  587.  
  588. $html .= '</select>'; 
  589.  
  590. // Displays option description. 
  591. if ( isset( $args['description'] ) ) { 
  592. $html .= sprintf( '<p class="description">%s</p>', $args['description'] ); 
  593.  
  594. echo $html; 
  595.  
  596. /** 
  597. * Displays a radio settings field 
  598. * 
  599. * @param array $args settings field args 
  600. */ 
  601. public function radio_element_callback( $args ) { 
  602. $menu = $args['menu']; 
  603. $id = $args['id']; 
  604.  
  605. $options = get_option( $menu ); 
  606.  
  607. if ( isset( $options[$id] ) ) { 
  608. $current = $options[$id]; 
  609. } else { 
  610. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  611.  
  612. $html = ''; 
  613. foreach ( $args['options'] as $key => $label ) { 
  614. $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 ) ); 
  615. $html .= sprintf( '<label for="%1$s[%2$s][%3$s]"> %4$s</label><br>', $menu, $id, $key, $label); 
  616.  
  617. // Displays option description. 
  618. if ( isset( $args['description'] ) ) { 
  619. $html .= sprintf( '<p class="description">%s</p>', $args['description'] ); 
  620.  
  621. echo $html; 
  622.  
  623.  
  624. /** 
  625. * Section null callback. 
  626. * 
  627. * @return void. 
  628. */ 
  629. public function section_options_callback() { 
  630.  
  631. /** 
  632. * Section null callback. 
  633. * 
  634. * @return void. 
  635. */ 
  636. public function custom_fields_section() { 
  637. $menu = $args['menu']; 
  638. $id = $args['id']; 
  639. $size = isset( $args['size'] ) ? $args['size'] : '25'; 
  640.  
  641. $options = get_option( $menu ); 
  642.  
  643. if ( isset( $options[$id] ) ) { 
  644. $current = $options[$id]; 
  645. } else { 
  646. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  647.  
  648. $html = sprintf( '<code>%1$s</code>', $current); 
  649.  
  650. // Displays option description. 
  651. if ( isset( $args['description'] ) ) { 
  652. $html .= sprintf( '<span class="description">%s</span>', $args['description'] ); 
  653.  
  654. echo $html; 
  655.  
  656. /** 
  657. * Validate options. 
  658. * 
  659. * @param array $input options to valid. 
  660. * 
  661. * @return array validated options. 
  662. */ 
  663. public function validate_options( $input ) { 
  664. // Create our array for storing the validated options. 
  665. $output = array(); 
  666.  
  667. // Loop through each of the incoming options. 
  668. foreach ( $input as $key => $value ) { 
  669.  
  670. // Check to see if the current option has a value. If so, process it. 
  671. if ( isset( $input[$key] ) ) { 
  672. // Strip all HTML and PHP tags and properly handle quoted strings. 
  673. if ( is_array( $input[$key] ) ) { 
  674. foreach ( $input[$key] as $sub_key => $sub_value ) { 
  675. $output[$key][$sub_key] = strip_tags( $input[$key][$sub_key] ); 
  676.  
  677. } else { 
  678. $output[$key] = strip_tags( $input[$key] ); 
  679.  
  680. // Return the array processing any additional functions filtered by this action. 
  681. return apply_filters( 'wcqc_validate_input', $output, $input ); 
  682.  
  683.  
  684.  
  685. } // end class WooCommerce_Qinvoice_Connect_Settings 
  686.  
  687. } // end class_exists 
.