WooCommerce_PDF_Invoices_Settings

The WooCommerce PDF Invoices & Packing Slips WooCommerce PDF Invoices Settings class.

Defined (1)

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

/includes/class-wcpdf-settings.php  
  1. class WooCommerce_PDF_Invoices_Settings { 
  2.  
  3. public $options_page_hook; 
  4. public $general_settings; 
  5. public $template_settings; 
  6.  
  7. public function __construct() { 
  8. add_action( 'admin_menu', array( &$this, 'menu' ) ); // Add menu. 
  9. add_action( 'admin_init', array( &$this, 'init_settings' ) ); // Registers settings 
  10. add_filter( 'option_page_capability_wpo_wcpdf_template_settings', array( &$this, 'settings_capabilities' ) ); 
  11. add_filter( 'option_page_capability_wpo_wcpdf_general_settings', array( &$this, 'settings_capabilities' ) ); 
  12. add_action( 'admin_enqueue_scripts', array( &$this, 'load_scripts_styles' ) ); // Load scripts 
  13.  
  14. // Add links to WordPress plugins page 
  15. add_filter( 'plugin_action_links_'.WooCommerce_PDF_Invoices::$plugin_basename, array( &$this, 'wpo_wcpdf_add_settings_link' ) ); 
  16. add_filter( 'plugin_row_meta', array( $this, 'add_support_links' ), 10, 2 ); 
  17.  
  18. $this->general_settings = get_option('wpo_wcpdf_general_settings'); 
  19. $this->template_settings = get_option('wpo_wcpdf_template_settings'); 
  20.  
  21. // WooCommerce Order Status & Actions Manager emails compatibility 
  22. add_filter( 'wpo_wcpdf_wc_emails', array( $this, 'wc_order_status_actions_emails' ), 10, 1 ); 
  23.  
  24. public function menu() { 
  25. $parent_slug = 'woocommerce'; 
  26.  
  27. $this->options_page_hook = add_submenu_page( 
  28. $parent_slug,  
  29. __( 'PDF Invoices', 'wpo_wcpdf' ),  
  30. __( 'PDF Invoices', 'wpo_wcpdf' ),  
  31. 'manage_woocommerce',  
  32. 'wpo_wcpdf_options_page',  
  33. array( $this, 'settings_page' ) 
  34. ); 
  35.  
  36. /** 
  37. * Set capability for settings page 
  38. */ 
  39. public function settings_capabilities() { 
  40. return 'manage_woocommerce'; 
  41. }  
  42.  
  43. /** 
  44. * Styles for settings page 
  45. */ 
  46. public function load_scripts_styles ( $hook ) { 
  47. if( $hook != $this->options_page_hook )  
  48. return; 
  49.  
  50. wp_enqueue_script( 
  51. 'wcpdf-upload-js',  
  52. plugins_url( 'js/media-upload.js' , dirname(__FILE__) ),  
  53. array( 'jquery' ),  
  54. WooCommerce_PDF_Invoices::$version 
  55. ); 
  56.  
  57. wp_enqueue_style( 
  58. 'wpo-wcpdf',  
  59. WooCommerce_PDF_Invoices::$plugin_url . 'css/style.css',  
  60. array(),  
  61. WooCommerce_PDF_Invoices::$version 
  62. ); 
  63. wp_enqueue_media(); 
  64.  
  65. /** 
  66. * Add settings link to plugins page 
  67. */ 
  68. public function wpo_wcpdf_add_settings_link( $links ) { 
  69. $settings_link = '<a href="admin.php?page=wpo_wcpdf_options_page">'. __( 'Settings', 'woocommerce' ) . '</a>'; 
  70. array_push( $links, $settings_link ); 
  71. return $links; 
  72.  
  73. /** 
  74. * Add various support links to plugin page 
  75. * after meta (version, authors, site) 
  76. */ 
  77. public function add_support_links( $links, $file ) { 
  78. if ( !current_user_can( 'install_plugins' ) ) { 
  79. return $links; 
  80.  
  81. if ( $file == WooCommerce_PDF_Invoices::$plugin_basename ) { 
  82. // $links[] = '<a href="..." target="_blank" title="' . __( '...', 'wpo_wcpdf' ) . '">' . __( '...', 'wpo_wcpdf' ) . '</a>'; 
  83. return $links; 
  84.  
  85. public function settings_page() { 
  86. $settings_tabs = apply_filters( 'wpo_wcpdf_settings_tabs', array ( 
  87. 'general' => __('General', 'wpo_wcpdf'),  
  88. 'template' => __('Template', 'wpo_wcpdf'),  
  89. ); 
  90.  
  91. // add status tab last in row 
  92. $settings_tabs['debug'] = __('Status', 'wpo_wcpdf'); 
  93.  
  94. $active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'general'; 
  95.  
  96. ?> 
  97. <script type="text/javascript"> 
  98. jQuery( function( $ ) { 
  99. $("#footer-thankyou").html("If you like <strong>WooCommerce PDF Invoices & Packing Slips</strong> please leave us a <a href='https://wordpress.org/support/view/plugin-reviews/woocommerce-pdf-invoices-packing-slips?rate=5#postform'>*****</a> rating. A huge thank you in advance!"); 
  100. }); 
  101. </script> 
  102. <div class="wrap"> 
  103. <div class="icon32" id="icon-options-general"><br /></div> 
  104. <h2><?php _e( 'WooCommerce PDF Invoices', 'wpo_wcpdf' ); ?></h2> 
  105. <h2 class="nav-tab-wrapper"> 
  106. <?php 
  107. foreach ($settings_tabs as $tab_slug => $tab_title ) { 
  108. printf('<a href="?page=wpo_wcpdf_options_page&tab=%1$s" class="nav-tab nav-tab-%1$s %2$s">%3$s</a>', $tab_slug, (($active_tab == $tab_slug) ? 'nav-tab-active' : ''), $tab_title); 
  109. ?> 
  110. </h2> 
  111.  
  112. <?php 
  113. do_action( 'wpo_wcpdf_before_settings_page', $active_tab ); 
  114.  
  115. // save or check option to hide extensions ad 
  116. if ( isset( $_GET['wpo_wcpdf_hide_extensions_ad'] ) ) { 
  117. update_option( 'wpo_wcpdf_hide_extensions_ad', true ); 
  118. $hide_ad = true; 
  119. } else { 
  120. $hide_ad = get_option( 'wpo_wcpdf_hide_extensions_ad' ); 
  121.  
  122. if ( !$hide_ad && !( class_exists('WooCommerce_PDF_IPS_Pro') && class_exists('WooCommerce_PDF_IPS_Dropbox') && class_exists('WooCommerce_PDF_IPS_Templates') && class_exists('WooCommerce_Ext_PrintOrders') ) ) { 
  123. include('wcpdf-extensions.php'); 
  124.  
  125. ?> 
  126. <form method="post" action="options.php" id="wpo-wcpdf-settings"> 
  127. <?php 
  128. do_action( 'wpo_wcpdf_before_settings', $active_tab ); 
  129. settings_fields( 'wpo_wcpdf_'.$active_tab.'_settings' ); 
  130. do_settings_sections( 'wpo_wcpdf_'.$active_tab.'_settings' ); 
  131. do_action( 'wpo_wcpdf_after_settings', $active_tab ); 
  132.  
  133. submit_button(); 
  134. ?> 
  135.  
  136. </form> 
  137. <?php 
  138.  
  139. if ( $active_tab=='debug' ) { 
  140. $this->status_page(); 
  141.  
  142. do_action( 'wpo_wcpdf_after_settings_page', $active_tab ); ?> 
  143.  
  144. </div> 
  145.  
  146. <?php 
  147.  
  148. public function status_page() { 
  149. ?> 
  150. <?php include('dompdf-status.php'); ?> 
  151. <?php 
  152.  
  153. /** 
  154. * User settings. 
  155. *  
  156. */ 
  157.  
  158. public function init_settings() { 
  159. global $woocommerce, $wpo_wcpdf; 
  160.  
  161. // Whether a third-party plugin claims responsibility for generating invoice numbers 
  162. $invoicenumber_thirdparty = apply_filters('woocommerce_invoice_number_by_plugin', false); 
  163.  
  164. /**************************************/ 
  165. /*********** GENERAL SETTINGS *********/ 
  166. /**************************************/ 
  167.  
  168. $option = 'wpo_wcpdf_general_settings'; 
  169.  
  170. // Create option in wp_options. 
  171. if ( false === get_option( $option ) ) { 
  172. $this->default_settings( $option ); 
  173.  
  174. // Section. 
  175. add_settings_section( 
  176. 'general_settings',  
  177. __( 'General settings', 'wpo_wcpdf' ),  
  178. array( &$this, 'section_options_callback' ),  
  179. $option 
  180. ); 
  181.  
  182. add_settings_field( 
  183. 'download_display',  
  184. __( 'How do you want to view the PDF?', 'wpo_wcpdf' ),  
  185. array( &$this, 'select_element_callback' ),  
  186. $option,  
  187. 'general_settings',  
  188. array( 
  189. 'menu' => $option,  
  190. 'id' => 'download_display',  
  191. 'options' => array( 
  192. 'download' => __( 'Download the PDF' , 'wpo_wcpdf' ),  
  193. 'display' => __( 'Open the PDF in a new browser tab/window' , 'wpo_wcpdf' ),  
  194. ),  
  195. ); 
  196.  
  197. $tmp_path = $wpo_wcpdf->export->tmp_path( 'attachments' ); 
  198. $tmp_path_check = !is_writable( $tmp_path ); 
  199.  
  200. $wc_emails = array( 
  201. 'new_order' => __( 'Admin New Order email' , 'wpo_wcpdf' ),  
  202. 'processing' => __( 'Customer Processing Order email' , 'wpo_wcpdf' ),  
  203. 'completed' => __( 'Customer Completed Order email' , 'wpo_wcpdf' ),  
  204. 'customer_invoice' => __( 'Customer Invoice email' , 'wpo_wcpdf' ),  
  205. ); 
  206.  
  207. // load custom emails 
  208. $extra_emails = $this->get_wc_emails(); 
  209. $wc_emails = array_merge( $wc_emails, $extra_emails ); 
  210.  
  211. add_settings_field( 
  212. 'email_pdf',  
  213. __( 'Attach invoice to:', 'wpo_wcpdf' ),  
  214. array( &$this, 'multiple_checkbox_element_callback' ),  
  215. $option,  
  216. 'general_settings',  
  217. array( 
  218. 'menu' => $option,  
  219. 'id' => 'email_pdf',  
  220. 'options' => apply_filters( 'wpo_wcpdf_wc_emails', $wc_emails ),  
  221. 'description' => $tmp_path_check ? '<span class="wpo-warning">' . sprintf( __( 'It looks like the temp folder (<code>%s</code>) is not writable, check the permissions for this folder! Without having write access to this folder, the plugin will not be able to email invoices.', 'wpo_wcpdf' ), $tmp_path ).'</span>':'',  
  222. ); 
  223.  
  224. add_settings_field( 
  225. 'disable_free',  
  226. __( 'Disable for free products', 'wpo_wcpdf' ),  
  227. array( &$this, 'checkbox_element_callback' ),  
  228. $option,  
  229. 'general_settings',  
  230. array( 
  231. 'menu' => $option,  
  232. 'id' => 'disable_free',  
  233. 'description' => __( "Disable automatic creation/attachment of invoices when only free products are ordered", 'wpo_wcpdf' ),  
  234. ); 
  235.  
  236. // Section. 
  237. add_settings_section( 
  238. 'interface',  
  239. __( 'Interface', 'wpo_wcpdf' ),  
  240. array( &$this, 'section_options_callback' ),  
  241. $option 
  242. ); 
  243.  
  244. // $documents = array( 
  245. // 'invoice' => __( 'Invoice', 'wpo_wcpdf' ),  
  246. // 'packing-slip' => __( 'Packing Slip', 'wpo_wcpdf' ),  
  247. // ); 
  248.  
  249. // $contexts = array( 
  250. // 'orders-list' => __( 'Orders list', 'wpo_wcpdf' ),  
  251. // 'orders-bulk' => __( 'Bulk order actions', 'wpo_wcpdf' ),  
  252. // 'order-single' => __( 'Single order page', 'wpo_wcpdf' ),  
  253. // 'my-account' => __( 'My Account page', 'wpo_wcpdf' ),  
  254. // ); 
  255.  
  256. // add_settings_field( 
  257. // 'buttons',  
  258. // __( 'Show download buttons', 'wpo_wcpdf' ),  
  259. // array( &$this, 'checkbox_table_callback' ),  
  260. // $option,  
  261. // 'interface',  
  262. // array( 
  263. // 'menu' => $option,  
  264. // 'id' => 'buttons',  
  265. // 'rows' => $contexts,  
  266. // 'columns' => apply_filters( 'wpo_wcpdf_documents_buttons', $documents ),  
  267. // ) 
  268. // ); 
  269.  
  270. // get list of WooCommerce statuses 
  271. if ( version_compare( WOOCOMMERCE_VERSION, '2.2', '<' ) ) { 
  272. $statuses = (array) get_terms( 'shop_order_status', array( 'hide_empty' => 0, 'orderby' => 'id' ) ); 
  273. foreach ( $statuses as $status ) { 
  274. $order_statuses[esc_attr( $status->slug )] = esc_html__( $status->name, 'woocommerce' ); 
  275. } else { 
  276. $statuses = wc_get_order_statuses(); 
  277. foreach ( $statuses as $status_slug => $status ) { 
  278. $status_slug = 'wc-' === substr( $status_slug, 0, 3 ) ? substr( $status_slug, 3 ) : $status_slug; 
  279. $order_statuses[$status_slug] = $status; 
  280.  
  281.  
  282. add_settings_field( 
  283. 'my_account_buttons',  
  284. __( 'Allow My Account invoice download', 'wpo_wcpdf' ),  
  285. array( &$this, 'select_element_callback' ),  
  286. $option,  
  287. 'interface',  
  288. array( 
  289. 'menu' => $option,  
  290. 'id' => 'my_account_buttons',  
  291. 'options' => array( 
  292. 'available' => __( 'Only when an invoice is already created/emailed' , 'wpo_wcpdf' ),  
  293. 'custom' => __( 'Only for specific order statuses (define below)' , 'wpo_wcpdf' ),  
  294. 'always' => __( 'Always' , 'wpo_wcpdf' ),  
  295. 'never' => __( 'Never' , 'wpo_wcpdf' ),  
  296. ),  
  297. 'custom' => array( 
  298. 'type' => 'multiple_checkbox_element_callback',  
  299. 'args' => array( 
  300. 'menu' => $option,  
  301. 'id' => 'my_account_restrict',  
  302. 'options' => $order_statuses,  
  303. ),  
  304. ),  
  305. ); 
  306.  
  307. add_settings_field( 
  308. 'invoice_number_column',  
  309. __( 'Enable invoice number column in the orders list', 'wpo_wcpdf' ),  
  310. array( &$this, 'checkbox_element_callback' ),  
  311. $option,  
  312. 'interface',  
  313. array( 
  314. 'menu' => $option,  
  315. 'id' => 'invoice_number_column',  
  316. ); 
  317.  
  318. // Register settings. 
  319. register_setting( $option, $option, array( &$this, 'validate_options' ) ); 
  320.  
  321. $option_values = get_option($option); 
  322. // convert old 'statusless' setting to new status array 
  323. if ( isset( $option_values['email_pdf'] ) && !is_array( $option_values['email_pdf'] ) ) { 
  324. $default_status = apply_filters( 'wpo_wcpdf_attach_to_status', 'completed' ); 
  325. $option_values['email_pdf'] = array ( 
  326. $default_status => 1,  
  327. 'customer_invoice' => 1,  
  328. ); 
  329. update_option( $option, $option_values ); 
  330.  
  331. /**************************************/ 
  332. /********** TEMPLATE SETTINGS *********/ 
  333. /**************************************/ 
  334.  
  335. $option = 'wpo_wcpdf_template_settings'; 
  336.  
  337. // Create option in wp_options. 
  338. if ( false === get_option( $option ) ) { 
  339. $this->default_settings( $option ); 
  340.  
  341. // Section. 
  342. add_settings_section( 
  343. 'template_settings',  
  344. __( 'PDF Template settings', 'wpo_wcpdf' ),  
  345. array( &$this, 'section_options_callback' ),  
  346. $option 
  347. ); 
  348.  
  349.  
  350. $theme_path = get_stylesheet_directory() . '/' . $wpo_wcpdf->export->template_base_path; 
  351. $theme_template_path = substr($theme_path, strpos($theme_path, 'wp-content')) . 'yourtemplate'; 
  352. $plugin_template_path = 'wp-content/plugins/woocommerce-pdf-invoices-packing-slips/templates/pdf/Simple'; 
  353.  
  354. add_settings_field( 
  355. 'template_path',  
  356. __( 'Choose a template', 'wpo_wcpdf' ),  
  357. array( &$this, 'template_select_element_callback' ),  
  358. $option,  
  359. 'template_settings',  
  360. array( 
  361. 'menu' => $option,  
  362. 'id' => 'template_path',  
  363. 'options' => $this->find_templates(),  
  364. 'description' => sprintf( __( 'Want to use your own template? Copy all the files from <code>%s</code> to your (child) theme in <code>%s</code> to customize them' , 'wpo_wcpdf' ), $plugin_template_path, $theme_template_path),  
  365. ); 
  366.  
  367. add_settings_field( 
  368. 'paper_size',  
  369. __( 'Paper size', 'wpo_wcpdf' ),  
  370. array( &$this, 'select_element_callback' ),  
  371. $option,  
  372. 'template_settings',  
  373. array( 
  374. 'menu' => $option,  
  375. 'id' => 'paper_size',  
  376. 'options' => apply_filters( 'wpo_wcpdf_template_settings_paper_size', array( 
  377. 'a4' => __( 'A4' , 'wpo_wcpdf' ),  
  378. 'letter' => __( 'Letter' , 'wpo_wcpdf' ),  
  379. ) ),  
  380. ); 
  381.  
  382. add_settings_field( 
  383. 'header_logo',  
  384. __( 'Shop header/logo', 'wpo_wcpdf' ),  
  385. array( &$this, 'media_upload_callback' ),  
  386. $option,  
  387. 'template_settings',  
  388. array( 
  389. 'menu' => $option,  
  390. 'id' => 'header_logo',  
  391. 'uploader_title' => __( 'Select or upload your invoice header/logo', 'wpo_wcpdf' ),  
  392. 'uploader_button_text' => __( 'Set image', 'wpo_wcpdf' ),  
  393. 'remove_button_text' => __( 'Remove image', 'wpo_wcpdf' ),  
  394. //'description' => __( '...', 'wpo_wcpdf' ),  
  395. ); 
  396.  
  397. add_settings_field( 
  398. 'shop_name',  
  399. __( 'Shop Name', 'wpo_wcpdf' ),  
  400. array( &$this, 'text_element_callback' ),  
  401. $option,  
  402. 'template_settings',  
  403. array( 
  404. 'menu' => $option,  
  405. 'id' => 'shop_name',  
  406. 'size' => '72',  
  407. 'translatable' => true,  
  408. ); 
  409.  
  410. add_settings_field( 
  411. 'shop_address',  
  412. __( 'Shop Address', 'wpo_wcpdf' ),  
  413. array( &$this, 'textarea_element_callback' ),  
  414. $option,  
  415. 'template_settings',  
  416. array( 
  417. 'menu' => $option,  
  418. 'id' => 'shop_address',  
  419. 'width' => '72',  
  420. 'height' => '8',  
  421. 'translatable' => true,  
  422. //'description' => __( '...', 'wpo_wcpdf' ),  
  423. ); 
  424.  
  425. add_settings_field( 
  426. 'footer',  
  427. __( 'Footer: terms & conditions, policies, etc.', 'wpo_wcpdf' ),  
  428. array( &$this, 'textarea_element_callback' ),  
  429. $option,  
  430. 'template_settings',  
  431. array( 
  432. 'menu' => $option,  
  433. 'id' => 'footer',  
  434. 'width' => '72',  
  435. 'height' => '4',  
  436. 'translatable' => true,  
  437. //'description' => __( '...', 'wpo_wcpdf' ),  
  438. ); 
  439.  
  440. // Section. 
  441. add_settings_section( 
  442. 'invoice',  
  443. __( 'Invoice', 'wpo_wcpdf' ),  
  444. array( &$this, 'section_options_callback' ),  
  445. $option 
  446. ); 
  447.  
  448. add_settings_field( 
  449. 'invoice_shipping_address',  
  450. __( 'Display shipping address', 'wpo_wcpdf' ),  
  451. array( &$this, 'checkbox_element_callback' ),  
  452. $option,  
  453. 'invoice',  
  454. array( 
  455. 'menu' => $option,  
  456. 'id' => 'invoice_shipping_address',  
  457. 'description' => __( 'Display shipping address on invoice (in addition to the default billing address) if different from billing address', 'wpo_wcpdf' ),  
  458. ); 
  459.  
  460. add_settings_field( 
  461. 'invoice_email',  
  462. __( 'Display email address', 'wpo_wcpdf' ),  
  463. array( &$this, 'checkbox_element_callback' ),  
  464. $option,  
  465. 'invoice',  
  466. array( 
  467. 'menu' => $option,  
  468. 'id' => 'invoice_email',  
  469. ); 
  470.  
  471. add_settings_field( 
  472. 'invoice_phone',  
  473. __( 'Display phone number', 'wpo_wcpdf' ),  
  474. array( &$this, 'checkbox_element_callback' ),  
  475. $option,  
  476. 'invoice',  
  477. array( 
  478. 'menu' => $option,  
  479. 'id' => 'invoice_phone',  
  480. ); 
  481.  
  482. add_settings_field( 
  483. 'display_date',  
  484. __( 'Display invoice date', 'wpo_wcpdf' ),  
  485. array( &$this, 'checkbox_element_callback' ),  
  486. $option,  
  487. 'invoice',  
  488. array( 
  489. 'menu' => $option,  
  490. 'id' => 'display_date',  
  491. 'value' => 'invoice_date',  
  492. ); 
  493.  
  494. if ($invoicenumber_thirdparty) { 
  495. $invoice_number_desc = __( 'Invoice numbers are created by a third-party extension.', 'yith-woocommerce-pdf-invoice'); 
  496. $config_link = esc_attr(apply_filters('woocommerce_invoice_number_configuration_link', null)); 
  497. if ($config_link) { 
  498. $invoice_number_desc .= ' '.sprintf(__( 'Configure it <a href="%s">here</a>.', 'yith-woocommerce-pdf-invoice'), $config_link); 
  499. $invoice_number_desc = '<i>'.$invoice_number_desc.'</i>'; 
  500. } else { 
  501. $invoice_number_desc = null; 
  502.  
  503. add_settings_field( 
  504. 'display_number',  
  505. $invoicenumber_thirdparty ? __( 'Display invoice number', 'wpo_wcpdf' ) : __( 'Display built-in sequential invoice number', 'wpo_wcpdf' ),  
  506. array( &$this, 'checkbox_element_callback' ),  
  507. $option,  
  508. 'invoice',  
  509. array( 
  510. 'menu' => $option,  
  511. 'id' => 'display_number',  
  512. 'value' => 'invoice_number',  
  513. 'description' => $invoice_number_desc,  
  514. ); 
  515.  
  516. if (!$invoicenumber_thirdparty) { 
  517. // invoice number is stored separately for direct retrieval 
  518. register_setting( $option, 'wpo_wcpdf_next_invoice_number', array( &$this, 'validate_options' ) ); 
  519. add_settings_field( 
  520. 'next_invoice_number',  
  521. __( 'Next invoice number (without prefix/suffix etc.)', 'wpo_wcpdf' ),  
  522. array( &$this, 'singular_text_element_callback' ),  
  523. $option,  
  524. 'invoice',  
  525. array( 
  526. 'menu' => 'wpo_wcpdf_next_invoice_number',  
  527. 'id' => 'next_invoice_number',  
  528. 'size' => '10',  
  529. 'description' => __( 'This is the number that will be used on the next invoice that is created. By default, numbering starts from the WooCommerce Order Number of the first invoice that is created and increases for every new invoice. Note that if you override this and set it lower than the highest (PDF) invoice number, this could create double invoice numbers!', 'wpo_wcpdf' ),  
  530. ); 
  531.  
  532. // first time invoice number 
  533. $next_invoice_number = get_option('wpo_wcpdf_next_invoice_number'); 
  534. // determine highest invoice number if option not set 
  535. if ( !isset( $next_invoice_number ) ) { 
  536. // Based on code from WooCommerce Sequential Order Numbers 
  537. global $wpdb; 
  538. // get highest invoice_number in postmeta table 
  539. $max_invoice_number = $wpdb->get_var( 'SELECT max(cast(meta_value as UNSIGNED)) from ' . $wpdb->postmeta . ' where meta_key="_wcpdf_invoice_number"' ); 
  540.  
  541. if ( !empty($max_invoice_number) ) { 
  542. $next_invoice_number = $max_invoice_number+1; 
  543. } else { 
  544. $next_invoice_number = ''; 
  545.  
  546. update_option( 'wpo_wcpdf_next_invoice_number', $next_invoice_number ); 
  547.  
  548. add_settings_field( 
  549. 'invoice_number_formatting',  
  550. __( 'Invoice number format', 'wpo_wcpdf' ),  
  551. array( &$this, 'invoice_number_formatting_callback' ),  
  552. $option,  
  553. 'invoice',  
  554. array( 
  555. 'menu' => $option,  
  556. 'id' => 'invoice_number_formatting',  
  557. 'fields' => array( 
  558. 'prefix' => array( 
  559. 'title' => __( 'Prefix' , 'wpo_wcpdf' ),  
  560. 'size' => 20,  
  561. 'description' => __( 'to use the invoice year and/or month, use [invoice_year] or [invoice_month] respectively' , 'wpo_wcpdf' ),  
  562. ),  
  563. 'suffix' => array( 
  564. 'title' => __( 'Suffix' , 'wpo_wcpdf' ),  
  565. 'size' => 20,  
  566. 'description' => '',  
  567. ),  
  568. 'padding' => array( 
  569. 'title' => __( 'Padding' , 'wpo_wcpdf' ),  
  570. 'size' => 2,  
  571. 'description' => __( 'enter the number of digits here - enter "6" to display 42 as 000042' , 'wpo_wcpdf' ),  
  572. ),  
  573. ),  
  574. 'description' => __( 'note: if you have already created a custom invoice number format with a filter, the above settings will be ignored' , 'wpo_wcpdf' ),  
  575. ); 
  576.  
  577. add_settings_field( 
  578. 'yearly_reset_invoice_number',  
  579. __( 'Reset invoice number yearly', 'wpo_wcpdf' ),  
  580. array( &$this, 'checkbox_element_callback' ),  
  581. $option,  
  582. 'invoice',  
  583. array( 
  584. 'menu' => $option,  
  585. 'id' => 'yearly_reset_invoice_number',  
  586. ); 
  587. } // End if ($invoicenumber_thirdparty) 
  588.  
  589. add_settings_field( 
  590. 'currency_font',  
  591. __( 'Extended currency symbol support', 'wpo_wcpdf' ),  
  592. array( &$this, 'checkbox_element_callback' ),  
  593. $option,  
  594. 'invoice',  
  595. array( 
  596. 'menu' => $option,  
  597. 'id' => 'currency_font',  
  598. 'description' => __( 'Enable this if your currency symbol is not displaying properly' , 'wpo_wcpdf' ),  
  599. );  
  600.  
  601. // Section. 
  602. add_settings_section( 
  603. 'packing_slip',  
  604. __( 'Packing Slip', 'wpo_wcpdf' ),  
  605. array( &$this, 'section_options_callback' ),  
  606. $option 
  607. ); 
  608.  
  609. add_settings_field( 
  610. 'packing_slip_billing_address',  
  611. __( 'Display billing address', 'wpo_wcpdf' ),  
  612. array( &$this, 'checkbox_element_callback' ),  
  613. $option,  
  614. 'packing_slip',  
  615. array( 
  616. 'menu' => $option,  
  617. 'id' => 'packing_slip_billing_address',  
  618. 'description' => __( 'Display billing address on packing slip (in addition to the default shipping address) if different from shipping address', 'wpo_wcpdf' ),  
  619. ); 
  620.  
  621. add_settings_field( 
  622. 'packing_slip_email',  
  623. __( 'Display email address', 'wpo_wcpdf' ),  
  624. array( &$this, 'checkbox_element_callback' ),  
  625. $option,  
  626. 'packing_slip',  
  627. array( 
  628. 'menu' => $option,  
  629. 'id' => 'packing_slip_email',  
  630. ); 
  631.  
  632. add_settings_field( 
  633. 'packing_slip_phone',  
  634. __( 'Display phone number', 'wpo_wcpdf' ),  
  635. array( &$this, 'checkbox_element_callback' ),  
  636. $option,  
  637. 'packing_slip',  
  638. array( 
  639. 'menu' => $option,  
  640. 'id' => 'packing_slip_phone',  
  641. ); 
  642.  
  643. // Section. 
  644. add_settings_section( 
  645. 'extra_template_fields',  
  646. __( 'Extra template fields', 'wpo_wcpdf' ),  
  647. array( &$this, 'custom_fields_section' ),  
  648. $option 
  649. ); 
  650.  
  651. add_settings_field( 
  652. 'extra_1',  
  653. __( 'Extra field 1', 'wpo_wcpdf' ),  
  654. array( &$this, 'textarea_element_callback' ),  
  655. $option,  
  656. 'extra_template_fields',  
  657. array( 
  658. 'menu' => $option,  
  659. 'id' => 'extra_1',  
  660. 'width' => '72',  
  661. 'height' => '8',  
  662. 'description' => __( 'This is footer column 1 in the <i>Modern (Premium)</i> template', 'wpo_wcpdf' ),  
  663. 'translatable' => true,  
  664. ); 
  665.  
  666. add_settings_field( 
  667. 'extra_2',  
  668. __( 'Extra field 2', 'wpo_wcpdf' ),  
  669. array( &$this, 'textarea_element_callback' ),  
  670. $option,  
  671. 'extra_template_fields',  
  672. array( 
  673. 'menu' => $option,  
  674. 'id' => 'extra_2',  
  675. 'width' => '72',  
  676. 'height' => '8',  
  677. 'description' => __( 'This is footer column 2 in the <i>Modern (Premium)</i> template', 'wpo_wcpdf' ),  
  678. 'translatable' => true,  
  679. ); 
  680.  
  681. add_settings_field( 
  682. 'extra_3',  
  683. __( 'Extra field 3', 'wpo_wcpdf' ),  
  684. array( &$this, 'textarea_element_callback' ),  
  685. $option,  
  686. 'extra_template_fields',  
  687. array( 
  688. 'menu' => $option,  
  689. 'id' => 'extra_3',  
  690. 'width' => '72',  
  691. 'height' => '8',  
  692. 'description' => __( 'This is footer column 3 in the <i>Modern (Premium)</i> template', 'wpo_wcpdf' ),  
  693. 'translatable' => true,  
  694. ); 
  695.  
  696. // Register settings. 
  697. register_setting( $option, $option, array( &$this, 'validate_options' ) ); 
  698.  
  699. /**************************************/ 
  700. /******** DEBUG/STATUS SETTINGS *******/ 
  701. /**************************************/ 
  702.  
  703. $option = 'wpo_wcpdf_debug_settings'; 
  704.  
  705. // Create option in wp_options. 
  706. if ( false === get_option( $option ) ) { 
  707. $this->default_settings( $option ); 
  708.  
  709. // Section. 
  710. add_settings_section( 
  711. 'debug_settings',  
  712. __( 'Debug settings', 'wpo_wcpdf' ),  
  713. array( &$this, 'debug_section' ),  
  714. $option 
  715. ); 
  716.  
  717. add_settings_field( 
  718. 'enable_debug',  
  719. __( 'Enable debug output', 'wpo_wcpdf' ),  
  720. array( &$this, 'checkbox_element_callback' ),  
  721. $option,  
  722. 'debug_settings',  
  723. array( 
  724. 'menu' => $option,  
  725. 'id' => 'enable_debug',  
  726. 'description' => __( "Enable this option to output plugin errors if you're getting a blank page or other PDF generation issues", 'wpo_wcpdf' ),  
  727. ); 
  728.  
  729. add_settings_field( 
  730. 'html_output',  
  731. __( 'Output to HTML', 'wpo_wcpdf' ),  
  732. array( &$this, 'checkbox_element_callback' ),  
  733. $option,  
  734. 'debug_settings',  
  735. array( 
  736. 'menu' => $option,  
  737. 'id' => 'html_output',  
  738. 'description' => __( 'Send the template output as HTML to the browser instead of creating a PDF.', 'wpo_wcpdf' ),  
  739. ); 
  740.  
  741. add_settings_field( 
  742. 'old_tmp',  
  743. __( 'Use old tmp folder', 'wpo_wcpdf' ),  
  744. array( &$this, 'checkbox_element_callback' ),  
  745. $option,  
  746. 'debug_settings',  
  747. array( 
  748. 'menu' => $option,  
  749. 'id' => 'old_tmp',  
  750. 'description' => __( 'Before version 1.5 of PDF Invoices, temporary files were stored in the plugin folder. This setting is only intended for backwards compatibility, not recommended on new installs!', 'wpo_wcpdf' ),  
  751. ); 
  752.  
  753. // Register settings. 
  754. register_setting( $option, $option, array( &$this, 'validate_options' ) ); 
  755.  
  756.  
  757. /** 
  758. * get all emails registered in WooCommerce 
  759. * @param boolean $remove_defaults switch to remove default woocommerce emails 
  760. * @return array $emails list of all email ids/slugs and names 
  761. */ 
  762. public function get_wc_emails ( $remove_defaults = true ) { 
  763. // get emails from WooCommerce 
  764. global $woocommerce; 
  765. $mailer = $woocommerce->mailer(); 
  766. $wc_emails = $mailer->get_emails(); 
  767.  
  768. $default_emails = array( 
  769. 'new_order',  
  770. 'customer_processing_order',  
  771. 'customer_completed_order',  
  772. 'customer_invoice',  
  773. 'customer_note',  
  774. 'customer_reset_password',  
  775. 'customer_new_account' 
  776. ); 
  777.  
  778. $emails = array(); 
  779. foreach ($wc_emails as $name => $template) { 
  780. if ( !( $remove_defaults && in_array( $template->id, $default_emails ) ) ) { 
  781. $emails[$template->id] = $template->title; 
  782.  
  783. return $emails; 
  784.  
  785. /** 
  786. * WooCommerce Order Status & Actions Manager emails compatibility 
  787. */ 
  788. public function wc_order_status_actions_emails ( $emails ) { 
  789. // check if WC_Custom_Status class is loaded! 
  790. if (class_exists('WC_Custom_Status')) { 
  791. // get list of custom statuses from WooCommerce Custom Order Status & Actions 
  792. // status slug => status name 
  793. $custom_statuses = WC_Custom_Status::get_status_list_names(); 
  794. // append _email to slug (=email_id) and add to emails list 
  795. foreach ($custom_statuses as $status_slug => $status_name) { 
  796. $emails[$status_slug.'_email'] = $status_name; 
  797. return $emails; 
  798.  
  799. /** 
  800. * Set default settings. 
  801. */ 
  802. public function default_settings( $option ) { 
  803. global $wpo_wcpdf; 
  804.  
  805. switch ( $option ) { 
  806. case 'wpo_wcpdf_general_settings': 
  807. $default = array( 
  808. 'download_display' => 'download',  
  809. ); 
  810. break; 
  811. case 'wpo_wcpdf_template_settings': 
  812. $default = array( 
  813. 'paper_size' => 'a4',  
  814. 'template_path' => $wpo_wcpdf->export->template_default_base_path . 'Simple',  
  815. // 'invoice_shipping_address' => '1',  
  816. ); 
  817. break; 
  818. default: 
  819. $default = array(); 
  820. break; 
  821.  
  822. if ( false === get_option( $option ) ) { 
  823. add_option( $option, $default ); 
  824. } else { 
  825. update_option( $option, $default ); 
  826.  
  827.  
  828. // Text element callback. 
  829. public function text_element_callback( $args ) { 
  830. $menu = $args['menu']; 
  831. $id = $args['id']; 
  832. $size = isset( $args['size'] ) ? $args['size'] : '25'; 
  833. $class = isset( $args['translatable'] ) && $args['translatable'] === true ? 'translatable' : ''; 
  834.  
  835. $options = get_option( $menu ); 
  836.  
  837. if ( isset( $options[$id] ) ) { 
  838. $current = $options[$id]; 
  839. } else { 
  840. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  841.  
  842. $html = sprintf( '<input type="text" id="%1$s" name="%2$s[%1$s]" value="%3$s" size="%4$s" class="%5$s"/>', $id, $menu, $current, $size, $class ); 
  843.  
  844. // Displays option description. 
  845. if ( isset( $args['description'] ) ) { 
  846. $html .= sprintf( '<p class="description">%s</p>', $args['description'] ); 
  847.  
  848. echo $html; 
  849.  
  850. // Single text option (not part of any settings array) 
  851. public function singular_text_element_callback( $args ) { 
  852. $menu = $args['menu']; 
  853. $id = $args['id']; 
  854. $size = isset( $args['size'] ) ? $args['size'] : '25'; 
  855. $class = isset( $args['translatable'] ) && $args['translatable'] === true ? 'translatable' : ''; 
  856.  
  857. $option = get_option( $menu ); 
  858.  
  859. if ( isset( $option ) ) { 
  860. $current = $option; 
  861. } else { 
  862. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  863.  
  864. $html = sprintf( '<input type="text" id="%1$s" name="%2$s" value="%3$s" size="%4$s" class="%5$s"/>', $id, $menu, $current, $size, $class ); 
  865.  
  866. // Displays option description. 
  867. if ( isset( $args['description'] ) ) { 
  868. $html .= sprintf( '<p class="description">%s</p>', $args['description'] ); 
  869.  
  870. echo $html; 
  871.  
  872. // Text element callback. 
  873. public function textarea_element_callback( $args ) { 
  874. $menu = $args['menu']; 
  875. $id = $args['id']; 
  876. $width = $args['width']; 
  877. $height = $args['height']; 
  878. $class = isset( $args['translatable'] ) && $args['translatable'] === true ? 'translatable' : ''; 
  879.  
  880. $options = get_option( $menu ); 
  881.  
  882. if ( isset( $options[$id] ) ) { 
  883. $current = $options[$id]; 
  884. } else { 
  885. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  886.  
  887. $html = sprintf( '<textarea id="%1$s" name="%2$s[%1$s]" cols="%4$s" rows="%5$s" class="%6$s"/>%3$s</textarea>', $id, $menu, $current, $width, $height, $class ); 
  888.  
  889. // Displays option description. 
  890. if ( isset( $args['description'] ) ) { 
  891. $html .= sprintf( '<p class="description">%s</p>', $args['description'] ); 
  892.  
  893. echo $html; 
  894.  
  895.  
  896. /** 
  897. * Checkbox field callback. 
  898. * @param array $args Field arguments. 
  899. * @return string Checkbox field. 
  900. */ 
  901. public function checkbox_element_callback( $args ) { 
  902. $menu = $args['menu']; 
  903. $id = $args['id']; 
  904. $value = isset( $args['value'] ) ? $args['value'] : 1; 
  905.  
  906. $options = get_option( $menu ); 
  907.  
  908. if ( isset( $options[$id] ) ) { 
  909. $current = $options[$id]; 
  910. } else { 
  911. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  912.  
  913. $html = sprintf( '<input type="checkbox" id="%1$s" name="%2$s[%1$s]" value="%3$s"%4$s />', $id, $menu, $value, checked( $value, $current, false ) ); 
  914.  
  915. // Displays option description. 
  916. if ( isset( $args['description'] ) ) { 
  917. $html .= sprintf( '<p class="description">%s</p>', $args['description'] ); 
  918.  
  919. echo $html; 
  920.  
  921. /** 
  922. * Multiple Checkbox field callback. 
  923. * @param array $args Field arguments. 
  924. * @return string Checkbox field. 
  925. */ 
  926. public function multiple_checkbox_element_callback( $args ) { 
  927. $menu = $args['menu']; 
  928. $id = $args['id']; 
  929.  
  930. $options = get_option( $menu ); 
  931.  
  932.  
  933. foreach ( $args['options'] as $key => $label ) { 
  934. $current = ( isset( $options[$id][$key] ) ) ? $options[$id][$key] : ''; 
  935. 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 ); 
  936.  
  937. // Displays option description. 
  938. if ( isset( $args['description'] ) ) { 
  939. printf( '<p class="description">%s</p>', $args['description'] ); 
  940.  
  941. /** 
  942. * Checkbox fields table callback. 
  943. * @param array $args Field arguments. 
  944. * @return string Checkbox field. 
  945. */ 
  946. public function checkbox_table_callback( $args ) { 
  947. $menu = $args['menu']; 
  948. $id = $args['id']; 
  949.  
  950. $options = get_option( $menu ); 
  951.  
  952. $rows = $args['rows']; 
  953. $columns = $args['columns']; 
  954.  
  955. ?> 
  956. <table style=""> 
  957. <tr> 
  958. <td style="padding:0 10px 5px 0;"> </td> 
  959. <?php foreach ( $columns as $column => $title ) { ?> 
  960. <td style="padding:0 10px 5px 0;"><?php echo $title; ?></td> 
  961. <?php } ?> 
  962. </tr> 
  963. <tr> 
  964. <td style="padding: 0;"> 
  965. <?php foreach ($rows as $row) { 
  966. echo $row.'<br/>'; 
  967. } ?> 
  968. </td> 
  969. <?php foreach ( $columns as $column => $title ) { ?> 
  970. <td style="text-align:center; padding: 0;"> 
  971. <?php foreach ( $rows as $row => $title ) { 
  972. $current = ( isset( $options[$id.'_'.$column][$row] ) ) ? $options[$id.'_'.$column][$row] : ''; 
  973. $name = sprintf('%1$s[%2$s_%3$s][%4$s]', $menu, $id, $column, $row); 
  974. printf( '<input type="checkbox" id="%1$s" name="%1$s" value="1"%2$s /><br/>', $name, checked( 1, $current, false ) ); 
  975. } ?> 
  976. </td> 
  977. <?php } ?> 
  978. </tr> 
  979. </table> 
  980.  
  981. <?php 
  982. // Displays option description. 
  983. if ( isset( $args['description'] ) ) { 
  984. printf( '<p class="description">%s</p>', $args['description'] ); 
  985.  
  986. /** 
  987. * Select element callback. 
  988. * @param array $args Field arguments. 
  989. * @return string Select field. 
  990. */ 
  991. public function select_element_callback( $args ) { 
  992. $menu = $args['menu']; 
  993. $id = $args['id']; 
  994.  
  995. $options = get_option( $menu ); 
  996.  
  997. if ( isset( $options[$id] ) ) { 
  998. $current = $options[$id]; 
  999. } else { 
  1000. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  1001.  
  1002. printf( '<select id="%1$s" name="%2$s[%1$s]">', $id, $menu ); 
  1003.  
  1004. foreach ( $args['options'] as $key => $label ) { 
  1005. printf( '<option value="%s"%s>%s</option>', $key, selected( $current, $key, false ), $label ); 
  1006.  
  1007. echo '</select>'; 
  1008.  
  1009.  
  1010. if (isset($args['custom'])) { 
  1011. $custom = $args['custom']; 
  1012.  
  1013. $custom_id = $id.'_custom'; 
  1014.  
  1015. printf( '<br/><br/><div id="%s" style="display:none;">', $custom_id ); 
  1016.  
  1017. switch ($custom['type']) { 
  1018. case 'text_element_callback': 
  1019. $this->text_element_callback( $custom['args'] ); 
  1020. break;  
  1021. case 'multiple_text_element_callback': 
  1022. $this->multiple_text_element_callback( $custom['args'] ); 
  1023. break;  
  1024. case 'multiple_checkbox_element_callback': 
  1025. $this->multiple_checkbox_element_callback( $custom['args'] ); 
  1026. break;  
  1027. default: 
  1028. break; 
  1029.  
  1030. echo '</div>'; 
  1031.  
  1032. ?> 
  1033. <script type="text/javascript"> 
  1034. jQuery(document).ready(function($) { 
  1035. function check_<?php echo $id; ?>_custom() { 
  1036. var custom = $('#<?php echo $id; ?>').val(); 
  1037. if (custom == 'custom') { 
  1038. $( '#<?php echo $custom_id; ?>').show(); 
  1039. } else { 
  1040. $( '#<?php echo $custom_id; ?>').hide(); 
  1041.  
  1042. check_<?php echo $id; ?>_custom(); 
  1043.  
  1044. $( '#<?php echo $id; ?>' ).change(function() { 
  1045. check_<?php echo $id; ?>_custom(); 
  1046. }); 
  1047.  
  1048. }); 
  1049. </script> 
  1050. <?php 
  1051.  
  1052. // Displays option description. 
  1053. if ( isset( $args['description'] ) ) { 
  1054. printf( '<p class="description">%s</p>', $args['description'] ); 
  1055.  
  1056.  
  1057. /** 
  1058. * Displays a radio settings field 
  1059. * @param array $args settings field args 
  1060. */ 
  1061. public function radio_element_callback( $args ) { 
  1062. $menu = $args['menu']; 
  1063. $id = $args['id']; 
  1064.  
  1065. $options = get_option( $menu ); 
  1066.  
  1067. if ( isset( $options[$id] ) ) { 
  1068. $current = $options[$id]; 
  1069. } else { 
  1070. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  1071.  
  1072. $html = ''; 
  1073. foreach ( $args['options'] as $key => $label ) { 
  1074. $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 ) ); 
  1075. $html .= sprintf( '<label for="%1$s[%2$s][%3$s]"> %4$s</label><br>', $menu, $id, $key, $label); 
  1076.  
  1077. // Displays option description. 
  1078. if ( isset( $args['description'] ) ) { 
  1079. $html .= sprintf( '<p class="description">%s</p>', $args['description'] ); 
  1080.  
  1081. echo $html; 
  1082.  
  1083. /** 
  1084. * Media upload callback. 
  1085. * @param array $args Field arguments. 
  1086. * @return string Media upload button & preview. 
  1087. */ 
  1088. public function media_upload_callback( $args ) { 
  1089. $menu = $args['menu']; 
  1090. $id = $args['id']; 
  1091. $options = get_option( $menu ); 
  1092.  
  1093. if ( isset( $options[$id] ) ) { 
  1094. $current = $options[$id]; 
  1095. } else { 
  1096. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  1097.  
  1098. $uploader_title = $args['uploader_title']; 
  1099. $uploader_button_text = $args['uploader_button_text']; 
  1100. $remove_button_text = $args['remove_button_text']; 
  1101.  
  1102. $html = ''; 
  1103. if( !empty($current) ) { 
  1104. $attachment = wp_get_attachment_image_src( $current, 'full', false ); 
  1105.  
  1106. $attachment_src = $attachment[0]; 
  1107. $attachment_width = $attachment[1]; 
  1108. $attachment_height = $attachment[2]; 
  1109.  
  1110. $attachment_resolution = round($attachment_height/(3/2.54)); 
  1111.  
  1112. $html .= sprintf('<img src="%1$s" style="display:block" id="img-%4$s"/>', $attachment_src, $attachment_width, $attachment_height, $id ); 
  1113. $html .= '<div class="attachment-resolution"><p class="description">'.__('Image resolution').': '.$attachment_resolution.'dpi (default height = 3cm)</p></div>'; 
  1114. $html .= sprintf('<span class="button wpo_remove_image_button" data-input_id="%1$s">%2$s</span>', $id, $remove_button_text ); 
  1115.  
  1116. $html .= sprintf( '<input id="%1$s" name="%2$s[%1$s]" type="hidden" value="%3$s" />', $id, $menu, $current ); 
  1117.  
  1118. $html .= sprintf( '<span class="button wpo_upload_image_button %4$s" data-uploader_title="%1$s" data-uploader_button_text="%2$s" data-remove_button_text="%3$s" data-input_id="%4$s">%2$s</span>', $uploader_title, $uploader_button_text, $remove_button_text, $id ); 
  1119.  
  1120. // Displays option description. 
  1121. if ( isset( $args['description'] ) ) { 
  1122. $html .= sprintf( '<p class="description">%s</p>', $args['description'] ); 
  1123.  
  1124. echo $html; 
  1125.  
  1126. /** 
  1127. * Invoice number formatting callback. 
  1128. * @param array $args Field arguments. 
  1129. * @return string Media upload button & preview. 
  1130. */ 
  1131. public function invoice_number_formatting_callback( $args ) { 
  1132. $menu = $args['menu']; 
  1133. $fields = $args['fields']; 
  1134. $options = get_option( $menu ); 
  1135.  
  1136. echo '<table>'; 
  1137. foreach ($fields as $key => $field) { 
  1138. $id = $args['id'] . '_' . $key; 
  1139.  
  1140. if ( isset( $options[$id] ) ) { 
  1141. $current = $options[$id]; 
  1142. } else { 
  1143. $current = ''; 
  1144.  
  1145. $title = $field['title']; 
  1146. $size = $field['size']; 
  1147. $description = isset( $field['description'] ) ? '<span style="font-style:italic;">'.$field['description'].'</span>' : ''; 
  1148.  
  1149. echo '<tr>'; 
  1150. printf( '<td style="padding:0 1em 0 0; ">%1$s:</td><td style="padding:0;"><input type="text" id="%2$s" name="%3$s[%2$s]" value="%4$s" size="%5$s"/></td><td style="padding:0 0 0 1em;">%6$s</td>', $title, $id, $menu, $current, $size, $description ); 
  1151. echo '</tr>'; 
  1152. echo '</table>'; 
  1153.  
  1154.  
  1155. // Displays option description. 
  1156. if ( isset( $args['description'] ) ) { 
  1157. printf( '<p class="description">%s</p>', $args['description'] ); 
  1158.  
  1159. // echo $html; 
  1160.  
  1161.  
  1162. /** 
  1163. * Template select element callback. 
  1164. * @param array $args Field arguments. 
  1165. * @return string Select field. 
  1166. */ 
  1167. public function template_select_element_callback( $args ) { 
  1168. $menu = $args['menu']; 
  1169. $id = $args['id']; 
  1170.  
  1171. $options = get_option( $menu ); 
  1172.  
  1173. if ( isset( $options[$id] ) ) { 
  1174. $current = $options[$id]; 
  1175. } else { 
  1176. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  1177.  
  1178. $html = sprintf( '<select id="%1$s" name="%2$s[%1$s]">', $id, $menu ); 
  1179.  
  1180. // backwards compatible template path (1.4.4+ uses relative paths instead of absolute) 
  1181. if (strpos($current, ABSPATH) !== false) { 
  1182. // check if folder exists, then strip site base path. 
  1183. if ( file_exists( $current ) ) { 
  1184. $current = str_replace( ABSPATH, '', $current ); 
  1185.  
  1186. foreach ( $args['options'] as $key => $label ) { 
  1187. $html .= sprintf( '<option value="%s"%s>%s</option>', $key, selected( $current, $key, false ), $label ); 
  1188.  
  1189. $html .= '</select>'; 
  1190.  
  1191. // Displays option description. 
  1192. if ( isset( $args['description'] ) ) { 
  1193. $html .= sprintf( '<p class="description">%s</p>', $args['description'] ); 
  1194.  
  1195. echo $html; 
  1196.  
  1197.  
  1198. /** 
  1199. * Section null callback. 
  1200. * @return void. 
  1201. */ 
  1202. public function section_options_callback() { 
  1203.  
  1204. /** 
  1205. * Debug section callback. 
  1206. * @return void. 
  1207. */ 
  1208. public function debug_section() { 
  1209. _e( '<b>Warning!</b> The settings below are meant for debugging/development only. Do not use them on a live website!' , 'wpo_wcpdf' ); 
  1210.  
  1211. /** 
  1212. * Custom fields section callback. 
  1213. * @return void. 
  1214. */ 
  1215. public function custom_fields_section() { 
  1216. _e( 'These are used for the (optional) footer columns in the <em>Modern (Premium)</em> template, but can also be used for other elements in your custom template' , 'wpo_wcpdf' ); 
  1217.  
  1218. /** 
  1219. * Validate options. 
  1220. * @param array $input options to valid. 
  1221. * @return array validated options. 
  1222. */ 
  1223. public function validate_options( $input ) { 
  1224. // Create our array for storing the validated options. 
  1225. $output = array(); 
  1226.  
  1227. if (empty($input) || !is_array($input)) { 
  1228. return $input; 
  1229.  
  1230. // Loop through each of the incoming options. 
  1231. foreach ( $input as $key => $value ) { 
  1232.  
  1233. // Check to see if the current option has a value. If so, process it. 
  1234. if ( isset( $input[$key] ) ) { 
  1235. if ( is_array( $input[$key] ) ) { 
  1236. foreach ( $input[$key] as $sub_key => $sub_value ) { 
  1237. $output[$key][$sub_key] = $input[$key][$sub_key]; 
  1238. } else { 
  1239. $output[$key] = $input[$key]; 
  1240.  
  1241. // Return the array processing any additional functions filtered by this action. 
  1242. return apply_filters( 'wpo_wcpdf_validate_input', $output, $input ); 
  1243.  
  1244. /** 
  1245. * List templates in plugin folder, theme folder & child theme folder 
  1246. * @return array template path => template name 
  1247. */ 
  1248. public function find_templates() { 
  1249. global $wpo_wcpdf; 
  1250. $installed_templates = array(); 
  1251.  
  1252. // get base paths 
  1253. $template_paths = array ( 
  1254. // note the order: child-theme before theme, so that array_unique filters out parent doubles 
  1255. 'default' => $wpo_wcpdf->export->template_default_base_path,  
  1256. 'child-theme' => get_stylesheet_directory() . '/' . $wpo_wcpdf->export->template_base_path,  
  1257. 'theme' => get_template_directory() . '/' . $wpo_wcpdf->export->template_base_path,  
  1258. ); 
  1259.  
  1260. $template_paths = apply_filters( 'wpo_wcpdf_template_paths', $template_paths ); 
  1261.  
  1262. foreach ($template_paths as $template_source => $template_path) { 
  1263. $dirs = (array) glob( $template_path . '*' , GLOB_ONLYDIR); 
  1264.  
  1265. foreach ($dirs as $dir) { 
  1266. if ( file_exists($dir."/invoice.php") && file_exists($dir."/packing-slip.php")) 
  1267. // we're stripping abspath to make the plugin settings more portable 
  1268. $installed_templates[ str_replace( ABSPATH, '', $dir )] = basename($dir); 
  1269.  
  1270. // remove parent doubles 
  1271. $installed_templates = array_unique($installed_templates); 
  1272.  
  1273. if (empty($installed_templates)) { 
  1274. // fallback to Simple template for servers with glob() disabled 
  1275. $simple_template_path = str_replace( ABSPATH, '', $template_paths['default'] . 'Simple' ); 
  1276. $installed_templates[$simple_template_path] = 'Simple'; 
  1277.  
  1278. return apply_filters( 'wpo_wcpdf_templates', $installed_templates ); 
  1279.  
  1280. } // end class WooCommerce_PDF_Invoices_Settings