PageRenderTime 54ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/woocommerce-admin-settings.php

https://github.com/CammoKing/woocommerce
PHP | 717 lines | 524 code | 133 blank | 60 comment | 123 complexity | 2086c3cad407a6cb7f5aaf04b0a0531f MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /**
  3. * Functions for the settings page in admin.
  4. *
  5. * The settings page contains options for the WooCommerce plugin - this file contains functions to display
  6. * and save the list of options.
  7. *
  8. * @author WooThemes
  9. * @category Admin
  10. * @package WooCommerce/Admin/Settings
  11. * @version 1.6.4
  12. */
  13. if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
  14. /** Store settings in this array */
  15. global $woocommerce_settings;
  16. /** Settings init */
  17. include( 'settings/settings-init.php' );
  18. if ( ! function_exists( 'woocommerce_settings' ) ) {
  19. /**
  20. * Settings page.
  21. *
  22. * Handles the display of the main woocommerce settings page in admin.
  23. *
  24. * @access public
  25. * @return void
  26. */
  27. function woocommerce_settings() {
  28. global $woocommerce, $woocommerce_settings;
  29. do_action( 'woocommerce_settings_start' );
  30. // Get current tab/section
  31. $current_tab = ( empty( $_GET['tab'] ) ) ? 'general' : sanitize_text_field( urldecode( $_GET['tab'] ) );
  32. $current_section = ( empty( $_REQUEST['section'] ) ) ? '' : sanitize_text_field( urldecode( $_REQUEST['section'] ) );
  33. // Save settings
  34. if ( ! empty( $_POST ) ) {
  35. if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-settings' ) )
  36. die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce' ) );
  37. if ( ! $current_section ) {
  38. $old_base_color = get_option('woocommerce_frontend_css_base_color');
  39. $old_base_color = get_option('woocommerce_frontend_css_base_color');
  40. include_once( 'settings/settings-save.php' );
  41. switch ( $current_tab ) {
  42. case "general" :
  43. case "pages" :
  44. case "catalog" :
  45. case "inventory" :
  46. case "shipping" :
  47. case "tax" :
  48. case "email" :
  49. woocommerce_update_options( $woocommerce_settings[$current_tab] );
  50. break;
  51. }
  52. do_action( 'woocommerce_update_options' );
  53. do_action( 'woocommerce_update_options_' . $current_tab );
  54. // Handle Colour Settings
  55. if ( $current_tab == 'general' && get_option('woocommerce_frontend_css') == 'yes' ) {
  56. // Save settings
  57. $primary = ( ! empty( $_POST['woocommerce_frontend_css_primary'] ) ) ? woocommerce_format_hex( $_POST['woocommerce_frontend_css_primary'] ) : '';
  58. $secondary = ( ! empty( $_POST['woocommerce_frontend_css_secondary'] ) ) ? woocommerce_format_hex( $_POST['woocommerce_frontend_css_secondary'] ) : '';
  59. $highlight = ( ! empty( $_POST['woocommerce_frontend_css_highlight'] ) ) ? woocommerce_format_hex( $_POST['woocommerce_frontend_css_highlight'] ) : '';
  60. $content_bg = ( ! empty( $_POST['woocommerce_frontend_css_content_bg'] ) ) ? woocommerce_format_hex( $_POST['woocommerce_frontend_css_content_bg'] ) : '';
  61. $subtext = ( ! empty( $_POST['woocommerce_frontend_css_subtext'] ) ) ? woocommerce_format_hex( $_POST['woocommerce_frontend_css_subtext'] ) : '';
  62. $colors = array(
  63. 'primary' => $primary,
  64. 'secondary' => $secondary,
  65. 'highlight' => $highlight,
  66. 'content_bg' => $content_bg,
  67. 'subtext' => $subtext
  68. );
  69. $old_colors = get_option( 'woocommerce_frontend_css_colors' );
  70. update_option( 'woocommerce_frontend_css_colors', $colors );
  71. if ( $old_colors != $colors )
  72. woocommerce_compile_less_styles();
  73. }
  74. } else {
  75. // If saving a shipping methods options, load 'er up
  76. if ( $current_tab == 'shipping' && class_exists( $current_section ) ) {
  77. $current_section_class = new $current_section();
  78. do_action( 'woocommerce_update_options_' . $current_tab . '_' . $current_section_class->id );
  79. // If saving an email's options, load theme
  80. } elseif ( $current_tab == 'email' ) {
  81. // Load mailer
  82. $mailer = $woocommerce->mailer();
  83. if ( class_exists( $current_section ) ) {
  84. $current_section_class = new $current_section();
  85. do_action( 'woocommerce_update_options_' . $current_tab . '_' . $current_section_class->id );
  86. } else {
  87. do_action( 'woocommerce_update_options_' . $current_tab . '_' . $current_section );
  88. }
  89. } else {
  90. // Save section only
  91. do_action( 'woocommerce_update_options_' . $current_tab . '_' . $current_section );
  92. }
  93. }
  94. // Clear any unwanted data
  95. $woocommerce->clear_product_transients();
  96. // Redirect back to the settings page
  97. $redirect = add_query_arg( 'saved', 'true' );
  98. if ( ! empty( $_POST['subtab'] ) ) $redirect = add_query_arg( 'subtab', esc_attr( str_replace( '#', '', $_POST['subtab'] ) ), $redirect );
  99. wp_safe_redirect( $redirect );
  100. exit;
  101. }
  102. // Get any returned messages
  103. $error = ( empty( $_GET['wc_error'] ) ) ? '' : urldecode( stripslashes( $_GET['wc_error'] ) );
  104. $message = ( empty( $_GET['wc_message'] ) ) ? '' : urldecode( stripslashes( $_GET['wc_message'] ) );
  105. if ( $error || $message ) {
  106. if ( $error ) {
  107. echo '<div id="message" class="error fade"><p><strong>' . esc_html( $error ) . '</strong></p></div>';
  108. } else {
  109. echo '<div id="message" class="updated fade"><p><strong>' . esc_html( $message ) . '</strong></p></div>';
  110. }
  111. } elseif ( ! empty( $_GET['saved'] ) ) {
  112. echo '<div id="message" class="updated fade"><p><strong>' . __( 'Your settings have been saved.', 'woocommerce' ) . '</strong></p></div>';
  113. }
  114. // Were the settings saved?
  115. if ( ! empty( $_GET['saved'] ) ) {
  116. do_action('woocommerce_settings_saved');
  117. }
  118. // Hide WC Link
  119. if (isset($_GET['hide-wc-extensions-message']))
  120. update_option('hide-wc-extensions-message', 1);
  121. // Install/page installer
  122. $install_complete = false;
  123. // Add pages button
  124. if (isset($_GET['install_woocommerce_pages']) && $_GET['install_woocommerce_pages']) {
  125. require_once( 'woocommerce-admin-install.php' );
  126. woocommerce_create_pages();
  127. update_option('skip_install_woocommerce_pages', 1);
  128. $install_complete = true;
  129. // Skip button
  130. } elseif (isset($_GET['skip_install_woocommerce_pages']) && $_GET['skip_install_woocommerce_pages']) {
  131. update_option('skip_install_woocommerce_pages', 1);
  132. $install_complete = true;
  133. }
  134. if ($install_complete) {
  135. ?>
  136. <div id="message" class="updated woocommerce-message wc-connect">
  137. <div class="squeezer">
  138. <h4><?php _e( '<strong>Congratulations!</strong> &#8211; WooCommerce has been installed and setup. Enjoy :)', 'woocommerce' ); ?></h4>
  139. <p><a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.woothemes.com/woocommerce/" data-text="A open-source (free) #ecommerce plugin for #WordPress that helps you sell anything. Beautifully." data-via="WooThemes" data-size="large" data-hashtags="WooCommerce">Tweet</a>
  140. <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></p>
  141. </div>
  142. </div>
  143. <?php
  144. // Flush rules after install
  145. flush_rewrite_rules( false );
  146. // Set installed option
  147. update_option('woocommerce_installed', 0);
  148. }
  149. ?>
  150. <div class="wrap woocommerce">
  151. <form method="post" id="mainform" action="" enctype="multipart/form-data">
  152. <div class="icon32 icon32-woocommerce-settings" id="icon-woocommerce"><br /></div><h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
  153. <?php
  154. $tabs = array(
  155. 'general' => __( 'General', 'woocommerce' ),
  156. 'catalog' => __( 'Catalog', 'woocommerce' ),
  157. 'pages' => __( 'Pages', 'woocommerce' ),
  158. 'inventory' => __( 'Inventory', 'woocommerce' ),
  159. 'tax' => __( 'Tax', 'woocommerce'),
  160. 'shipping' => __( 'Shipping', 'woocommerce' ),
  161. 'payment_gateways' => __( 'Payment Gateways', 'woocommerce' ),
  162. 'email' => __( 'Emails', 'woocommerce' ),
  163. 'integration' => __( 'Integration', 'woocommerce' )
  164. );
  165. $tabs = apply_filters('woocommerce_settings_tabs_array', $tabs);
  166. foreach ( $tabs as $name => $label ) {
  167. echo '<a href="' . admin_url( 'admin.php?page=woocommerce_settings&tab=' . $name ) . '" class="nav-tab ';
  168. if( $current_tab == $name ) echo 'nav-tab-active';
  169. echo '">' . $label . '</a>';
  170. }
  171. do_action( 'woocommerce_settings_tabs' );
  172. ?>
  173. </h2>
  174. <?php wp_nonce_field( 'woocommerce-settings', '_wpnonce', true, true ); ?>
  175. <?php if ( ! get_option('hide-wc-extensions-message') ) : ?>
  176. <div id="woocommerce_extensions"><a href="<?php echo add_query_arg('hide-wc-extensions-message', 'true') ?>" class="hide">&times;</a><?php printf(__( 'More functionality and gateway options available via <a href="%s" target="_blank">WC official extensions</a>.', 'woocommerce' ), 'http://www.woothemes.com/extensions/woocommerce-extensions/'); ?></div>
  177. <?php endif; ?>
  178. <?php
  179. switch ($current_tab) :
  180. case "general" :
  181. include_once('settings/settings-frontend-styles.php');
  182. woocommerce_admin_fields( $woocommerce_settings[$current_tab] );
  183. break;
  184. case "tax" :
  185. include('settings/settings-tax-rates.php');
  186. woocommerce_admin_fields( $woocommerce_settings[$current_tab] );
  187. break;
  188. case "pages" :
  189. case "catalog" :
  190. case "inventory" :
  191. woocommerce_admin_fields( $woocommerce_settings[$current_tab] );
  192. break;
  193. case "email" :
  194. $current = $current_section ? '' : 'class="current"';
  195. $links = array( '<a href="' . admin_url( 'admin.php?page=woocommerce_settings&tab=email' ) . '" ' . $current . '>' . __( 'Email Options', 'woocommerce' ) . '</a>' );
  196. // Define emails that can be customised here
  197. $mailer = $woocommerce->mailer();
  198. $email_templates = $mailer->get_emails();
  199. foreach ( $email_templates as $email ) {
  200. $title = empty( $email->title ) ? ucwords( $email->id ) : ucwords( $email->title );
  201. $current = ( get_class( $email ) == $current_section ) ? 'class="current"' : '';
  202. $links[] = '<a href="' . add_query_arg( 'section', get_class( $email ), admin_url('admin.php?page=woocommerce_settings&tab=email') ) . '"' . $current . '>' . esc_html( $title ) . '</a>';
  203. }
  204. echo '<ul class="subsubsub"><li>' . implode( ' | </li><li>', $links ) . '</li></ul><br class="clear" />';
  205. // Specific email options
  206. if ( $current_section ) {
  207. foreach ( $email_templates as $email ) {
  208. if ( get_class( $email ) == $current_section ) {
  209. $email->admin_options();
  210. break;
  211. }
  212. }
  213. } else {
  214. woocommerce_admin_fields( $woocommerce_settings[ $current_tab ] );
  215. }
  216. break;
  217. case "shipping" :
  218. include('settings/settings-shipping-methods.php');
  219. $current = $current_section ? '' : 'class="current"';
  220. $links = array( '<a href="' . admin_url('admin.php?page=woocommerce_settings&tab=shipping') . '" ' . $current . '>' . __( 'Shipping Options', 'woocommerce' ) . '</a>' );
  221. // Load shipping methods so we can show any global options they may have
  222. $shipping_methods = $woocommerce->shipping->load_shipping_methods();
  223. foreach ( $shipping_methods as $method ) {
  224. if ( ! $method->has_settings() ) continue;
  225. $title = empty( $method->method_title ) ? ucwords( $method->id ) : ucwords( $method->method_title );
  226. $current = ( get_class( $method ) == $current_section ) ? 'class="current"' : '';
  227. $links[] = '<a href="' . add_query_arg( 'section', get_class( $method ), admin_url('admin.php?page=woocommerce_settings&tab=shipping') ) . '"' . $current . '>' . esc_html( $title ) . '</a>';
  228. }
  229. echo '<ul class="subsubsub"><li>' . implode( ' | </li><li>', $links ) . '</li></ul><br class="clear" />';
  230. // Specific method options
  231. if ( $current_section ) {
  232. foreach ( $shipping_methods as $method ) {
  233. if ( get_class( $method ) == $current_section && $method->has_settings() ) {
  234. $method->admin_options();
  235. break;
  236. }
  237. }
  238. } else {
  239. woocommerce_admin_fields( $woocommerce_settings[$current_tab] );
  240. }
  241. break;
  242. case "payment_gateways" :
  243. include('settings/settings-payment-gateways.php');
  244. $links = array( '<a href="#payment-gateways">'.__( 'Payment Gateways', 'woocommerce' ).'</a>' );
  245. foreach ( $woocommerce->payment_gateways->payment_gateways() as $gateway ) :
  246. $title = empty( $gateway->method_title ) ? ucwords( $gateway->id ) : ucwords( $gateway->method_title );
  247. $links[] = '<a href="#gateway-'.$gateway->id.'">' . esc_html( $title ) . '</a>';
  248. endforeach;
  249. echo '<div class="subsubsub_section"><ul class="subsubsub"><li>' . implode( ' | </li><li>', $links ) . '</li></ul><br class="clear" />';
  250. echo '<div class="section" id="payment-gateways">';
  251. woocommerce_admin_fields( $woocommerce_settings[$current_tab] );
  252. echo '</div>';
  253. // Specific method options
  254. foreach ( $woocommerce->payment_gateways->payment_gateways() as $gateway ) {
  255. echo '<div class="section" id="gateway-'.$gateway->id.'">';
  256. $gateway->admin_options();
  257. echo '</div>';
  258. }
  259. echo '</div>';
  260. break;
  261. case "integration" :
  262. $integrations = $woocommerce->integrations->get_integrations();
  263. $current_section = empty( $current_section ) ? key( $integrations ) : $current_section;
  264. foreach ( $integrations as $integration ) {
  265. $title = empty( $integration->method_title ) ? ucwords( $integration->id ) : ucwords( $integration->method_title );
  266. $current = ( $integration->id == $current_section ) ? 'class="current"' : '';
  267. $links[] = '<a href="' . add_query_arg( 'section', $integration->id, admin_url('admin.php?page=woocommerce_settings&tab=integration') ) . '"' . $current . '>' . esc_html( $title ) . '</a>';
  268. }
  269. echo '<ul class="subsubsub"><li>' . implode( ' | </li><li>', $links ) . '</li></ul><br class="clear" />';
  270. if ( isset( $integrations[ $current_section ] ) )
  271. $integrations[ $current_section ]->admin_options();
  272. break;
  273. default :
  274. do_action( 'woocommerce_settings_tabs_' . $current_tab );
  275. break;
  276. endswitch;
  277. ?>
  278. <p class="submit">
  279. <?php if ( ! isset( $GLOBALS['hide_save_button'] ) ) : ?>
  280. <input name="save" class="button-primary" type="submit" value="<?php _e( 'Save changes', 'woocommerce' ); ?>" />
  281. <?php endif; ?>
  282. <input type="hidden" name="subtab" id="last_tab" />
  283. </p>
  284. </form>
  285. <script type="text/javascript">
  286. jQuery(window).load(function(){
  287. // Subsubsub tabs
  288. jQuery('div.subsubsub_section ul.subsubsub li a:eq(0)').addClass('current');
  289. jQuery('div.subsubsub_section .section:gt(0)').hide();
  290. jQuery('div.subsubsub_section ul.subsubsub li a').click(function(){
  291. var $clicked = jQuery(this);
  292. var $section = $clicked.closest('.subsubsub_section');
  293. var $target = $clicked.attr('href');
  294. $section.find('a').removeClass('current');
  295. if ( $section.find('.section:visible').size() > 0 ) {
  296. $section.find('.section:visible').fadeOut( 100, function() {
  297. $section.find( $target ).fadeIn('fast');
  298. });
  299. } else {
  300. $section.find( $target ).fadeIn('fast');
  301. }
  302. $clicked.addClass('current');
  303. jQuery('#last_tab').val( $target );
  304. return false;
  305. });
  306. <?php if ( ! empty( $_GET['subtab'] ) ) echo 'jQuery("div.subsubsub_section ul.subsubsub li a[href=#' . esc_js( $_GET['subtab'] ) . ']").click();'; ?>
  307. // Countries
  308. jQuery('select#woocommerce_allowed_countries').change(function(){
  309. if (jQuery(this).val()=="specific") {
  310. jQuery(this).parent().parent().next('tr').show();
  311. } else {
  312. jQuery(this).parent().parent().next('tr').hide();
  313. }
  314. }).change();
  315. // Color picker
  316. jQuery('.colorpick').each(function(){
  317. jQuery('.colorpickdiv', jQuery(this).parent()).farbtastic(this);
  318. jQuery(this).click(function() {
  319. if ( jQuery(this).val() == "" ) jQuery(this).val('#');
  320. jQuery('.colorpickdiv', jQuery(this).parent() ).show();
  321. });
  322. });
  323. jQuery(document).mousedown(function(){
  324. jQuery('.colorpickdiv').hide();
  325. });
  326. // Edit prompt
  327. jQuery(function(){
  328. var changed = false;
  329. jQuery('input, textarea, select, checkbox').change(function(){
  330. changed = true;
  331. });
  332. jQuery('.woo-nav-tab-wrapper a').click(function(){
  333. if (changed) {
  334. window.onbeforeunload = function() {
  335. return '<?php echo __( 'The changes you made will be lost if you navigate away from this page.', 'woocommerce' ); ?>';
  336. }
  337. } else {
  338. window.onbeforeunload = '';
  339. }
  340. });
  341. jQuery('.submit input').click(function(){
  342. window.onbeforeunload = '';
  343. });
  344. });
  345. // Sorting
  346. jQuery('table.wc_gateways tbody, table.wc_shipping tbody').sortable({
  347. items:'tr',
  348. cursor:'move',
  349. axis:'y',
  350. handle: 'td',
  351. scrollSensitivity:40,
  352. helper:function(e,ui){
  353. ui.children().each(function(){
  354. jQuery(this).width(jQuery(this).width());
  355. });
  356. ui.css('left', '0');
  357. return ui;
  358. },
  359. start:function(event,ui){
  360. ui.item.css('background-color','#f6f6f6');
  361. },
  362. stop:function(event,ui){
  363. ui.item.removeAttr('style');
  364. }
  365. });
  366. // Chosen selects
  367. jQuery("select.chosen_select").chosen();
  368. jQuery("select.chosen_select_nostd").chosen({
  369. allow_single_deselect: 'true'
  370. });
  371. });
  372. </script>
  373. </div>
  374. <?php
  375. }
  376. }
  377. /**
  378. * Output admin fields.
  379. *
  380. * Loops though the woocommerce options array and outputs each field.
  381. *
  382. * @access public
  383. * @param array $options Opens array to output
  384. * @return void
  385. */
  386. function woocommerce_admin_fields( $options ) {
  387. global $woocommerce;
  388. foreach ( $options as $value ) {
  389. if ( ! isset( $value['type'] ) ) continue;
  390. if ( ! isset( $value['id'] ) ) $value['id'] = '';
  391. if ( ! isset( $value['name'] ) ) $value['name'] = '';
  392. if ( ! isset( $value['class'] ) ) $value['class'] = '';
  393. if ( ! isset( $value['css'] ) ) $value['css'] = '';
  394. if ( ! isset( $value['std'] ) ) $value['std'] = '';
  395. if ( ! isset( $value['desc'] ) ) $value['desc'] = '';
  396. if ( ! isset( $value['desc_tip'] ) ) $value['desc_tip'] = false;
  397. // Custom attribute handling
  398. $custom_attributes = array();
  399. if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) )
  400. foreach ( $value['custom_attributes'] as $attribute => $attribute_value )
  401. $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
  402. if ( $value['desc_tip'] === true ) {
  403. $description = '<img class="help_tip" data-tip="' . esc_attr( $value['desc'] ) . '" src="' . $woocommerce->plugin_url() . '/assets/images/help.png" />';
  404. } elseif ( $value['desc_tip'] ) {
  405. $description = '<img class="help_tip" data-tip="' . esc_attr( $value['desc_tip'] ) . '" src="' . $woocommerce->plugin_url() . '/assets/images/help.png" />';
  406. } else {
  407. $description = '<span class="description">' . wp_kses_post( $value['desc'] ) . '</span>';
  408. }
  409. switch( $value['type'] ) {
  410. case 'title':
  411. if ( isset($value['name'] ) && $value['name'] ) echo '<h3>' . esc_html( $value['name'] ) . '</h3>';
  412. if ( isset($value['desc'] ) && $value['desc'] ) echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) );
  413. echo '<table class="form-table">'. "\n\n";
  414. if ( isset($value['id'] ) && $value['id'] ) do_action( 'woocommerce_settings_' . sanitize_title($value['id'] ) );
  415. break;
  416. case 'sectionend':
  417. if ( isset($value['id'] ) && $value['id'] ) do_action( 'woocommerce_settings_' . sanitize_title( $value['id'] ) . '_end' );
  418. echo '</table>';
  419. if ( isset($value['id'] ) && $value['id'] ) do_action( 'woocommerce_settings_' . sanitize_title( $value['id'] ) . '_after' );
  420. break;
  421. case 'text':
  422. case 'email':
  423. case 'number':
  424. ?><tr valign="top">
  425. <th scope="row" class="titledesc">
  426. <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['name'] ); ?></label>
  427. </th>
  428. <td class="forminp"><input name="<?php echo esc_attr( $value['id'] ); ?>" id="<?php echo esc_attr( $value['id'] ); ?>" type="<?php echo esc_attr( $value['type'] ); ?>" style="<?php echo esc_attr( $value['css'] ); ?>" value="<?php if ( get_option( $value['id'] ) !== false && get_option( $value['id'] ) !== null ) { echo esc_attr( stripslashes( get_option($value['id'] ) ) ); } else { echo esc_attr( $value['std'] ); } ?>" <?php echo implode( ' ', $custom_attributes ); ?> /> <?php echo $description; ?></td>
  429. </tr><?php
  430. break;
  431. case 'color' :
  432. ?><tr valign="top">
  433. <th scope="row" class="titledesc">
  434. <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['name'] ); ?></label>
  435. </th>
  436. <td class="forminp"><input name="<?php echo esc_attr( $value['id'] ); ?>" id="<?php echo esc_attr( $value['id'] ); ?>" type="text" style="<?php echo esc_attr( $value['css'] ); ?>" value="<?php if ( get_option( $value['id'] ) !== false && get_option( $value['id'] ) !== null ) { echo esc_attr( stripslashes( get_option($value['id'] ) ) ); } else { echo esc_attr( $value['std'] ); } ?>" class="colorpick" <?php echo implode( ' ', $custom_attributes ); ?> /> <?php echo $description; ?> <div id="colorPickerDiv_<?php echo esc_attr( $value['id'] ); ?>" class="colorpickdiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"></div></td>
  437. </tr><?php
  438. break;
  439. case 'image_width' :
  440. ?><tr valign="top">
  441. <th scope="row" class="titledesc"><?php echo esc_html( $value['name'] ) ?></th>
  442. <td class="forminp">
  443. <?php _e( 'Width', 'woocommerce' ); ?> <input name="<?php echo esc_attr( $value['id'] ); ?>_width" id="<?php echo esc_attr( $value['id'] ); ?>_width" type="text" size="3" value="<?php if ( $size = get_option( $value['id'].'_width') ) echo stripslashes($size); else echo $value['std']; ?>" />
  444. <?php _e( 'Height', 'woocommerce' ); ?> <input name="<?php echo esc_attr( $value['id'] ); ?>_height" id="<?php echo esc_attr( $value['id'] ); ?>_height" type="text" size="3" value="<?php if ( $size = get_option( $value['id'].'_height') ) echo stripslashes($size); else echo $value['std']; ?>" />
  445. <label><?php _e( 'Hard Crop', 'woocommerce' ); ?> <input name="<?php echo esc_attr( $value['id'] ); ?>_crop" id="<?php echo esc_attr( $value['id'] ); ?>_crop" type="checkbox" <?php if (get_option( $value['id'].'_crop')!='') checked(get_option( $value['id'].'_crop'), 1); else checked(1); ?> /></label>
  446. <?php echo $description; ?></td>
  447. </tr><?php
  448. break;
  449. case 'select':
  450. ?><tr valign="top">
  451. <th scope="row" class="titledesc">
  452. <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['name'] ); ?></label>
  453. </th>
  454. <td class="forminp"><select name="<?php echo esc_attr( $value['id'] ); ?>" id="<?php echo esc_attr( $value['id'] ); ?>" style="<?php echo esc_attr( $value['css'] ); ?>" class="<?php if (isset($value['class'])) echo $value['class']; ?>" <?php echo implode( ' ', $custom_attributes ); ?>>
  455. <?php
  456. foreach ($value['options'] as $key => $val) {
  457. $_current = get_option( $value['id'] );
  458. if ( ! $_current ) {
  459. $_current = $value['std'];
  460. }
  461. ?>
  462. <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $_current, $key ); ?>><?php echo $val ?></option>
  463. <?php
  464. }
  465. ?>
  466. </select> <?php echo $description; ?>
  467. </td>
  468. </tr><?php
  469. break;
  470. case 'checkbox' :
  471. if (!isset($value['hide_if_checked'])) $value['hide_if_checked'] = false;
  472. if (!isset($value['show_if_checked'])) $value['show_if_checked'] = false;
  473. if (!isset($value['checkboxgroup']) || (isset($value['checkboxgroup']) && $value['checkboxgroup']=='start')) :
  474. ?>
  475. <tr valign="top" class="<?php
  476. if ($value['hide_if_checked']=='yes' || $value['show_if_checked']=='yes') echo 'hidden_option';
  477. if ($value['hide_if_checked']=='option') echo 'hide_options_if_checked';
  478. if ($value['show_if_checked']=='option') echo 'show_options_if_checked';
  479. ?>">
  480. <th scope="row" class="titledesc"><?php echo esc_html( $value['name'] ) ?></th>
  481. <td class="forminp">
  482. <fieldset>
  483. <?php
  484. else :
  485. ?>
  486. <fieldset class="<?php
  487. if ($value['hide_if_checked']=='yes' || $value['show_if_checked']=='yes') echo 'hidden_option';
  488. if ($value['hide_if_checked']=='option') echo 'hide_options_if_checked';
  489. if ($value['show_if_checked']=='option') echo 'show_options_if_checked';
  490. ?>">
  491. <?php
  492. endif;
  493. ?>
  494. <legend class="screen-reader-text"><span><?php echo esc_html( $value['name'] ) ?></span></legend>
  495. <label for="<?php echo $value['id'] ?>">
  496. <input name="<?php echo esc_attr( $value['id'] ); ?>" id="<?php echo esc_attr( $value['id'] ); ?>" type="checkbox" value="1" <?php checked(get_option($value['id']), 'yes'); ?> <?php echo implode( ' ', $custom_attributes ); ?> />
  497. <?php echo wp_kses_post( $value['desc'] ) ?></label> <?php if ( $value['desc_tip'] ) echo $description; ?><br />
  498. <?php
  499. if (!isset($value['checkboxgroup']) || (isset($value['checkboxgroup']) && $value['checkboxgroup']=='end')) :
  500. ?>
  501. </fieldset>
  502. </td>
  503. </tr>
  504. <?php
  505. else :
  506. ?>
  507. </fieldset>
  508. <?php
  509. endif;
  510. break;
  511. case 'textarea':
  512. ?><tr valign="top">
  513. <th scope="row" class="titledesc">
  514. <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['name'] ); ?></label>
  515. </th>
  516. <td class="forminp">
  517. <?php if ( ! empty( $value['desc'] ) ) echo '<p style="margin-top:0;">' . wp_kses_post( $value['desc'] ) . '</p>'; ?>
  518. <textarea <?php if ( isset($value['args']) ) echo $value['args'] . ' '; ?>name="<?php echo esc_attr( $value['id'] ); ?>" id="<?php echo esc_attr( $value['id'] ); ?>" style="<?php echo esc_attr( $value['css'] ); ?>" <?php echo implode( ' ', $custom_attributes ); ?>><?php if (false !== get_option($value['id'])) echo esc_textarea(stripslashes(get_option($value['id']))); else echo esc_textarea( $value['std'] ); ?></textarea>
  519. </td>
  520. </tr><?php
  521. break;
  522. case 'single_select_page' :
  523. $page_setting = (int) get_option($value['id']);
  524. $args = array( 'name' => $value['id'],
  525. 'id' => $value['id'],
  526. 'sort_column' => 'menu_order',
  527. 'sort_order' => 'ASC',
  528. 'show_option_none' => ' ',
  529. 'class' => $value['class'],
  530. 'echo' => false,
  531. 'selected' => $page_setting);
  532. if( isset($value['args']) ) $args = wp_parse_args($value['args'], $args);
  533. ?><tr valign="top" class="single_select_page">
  534. <th scope="row" class="titledesc"><?php echo esc_html( $value['name'] ) ?></th>
  535. <td class="forminp">
  536. <?php echo str_replace(' id=', " data-placeholder='".__( 'Select a page&hellip;', 'woocommerce' )."' style='".$value['css']."' class='".$value['class']."' id=", wp_dropdown_pages($args)); ?> <?php echo $description; ?>
  537. </td>
  538. </tr><?php
  539. break;
  540. case 'single_select_country' :
  541. $countries = $woocommerce->countries->countries;
  542. $country_setting = (string) get_option($value['id']);
  543. if (strstr($country_setting, ':')) :
  544. $country = current(explode(':', $country_setting));
  545. $state = end(explode(':', $country_setting));
  546. else :
  547. $country = $country_setting;
  548. $state = '*';
  549. endif;
  550. ?><tr valign="top">
  551. <th scope="row" class="titledesc">
  552. <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['name'] ); ?></label>
  553. </th>
  554. <td class="forminp"><select name="<?php echo esc_attr( $value['id'] ); ?>" style="<?php echo esc_attr( $value['css'] ); ?>" data-placeholder="<?php _e( 'Choose a country&hellip;', 'woocommerce' ); ?>" title="Country" class="chosen_select">
  555. <?php echo $woocommerce->countries->country_dropdown_options($country, $state); ?>
  556. </select> <?php echo $description; ?>
  557. </td>
  558. </tr><?php
  559. break;
  560. case 'multi_select_countries' :
  561. $countries = $woocommerce->countries->countries;
  562. asort($countries);
  563. $selections = (array) get_option($value['id']);
  564. ?><tr valign="top">
  565. <th scope="row" class="titledesc">
  566. <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['name'] ); ?></label>
  567. </th>
  568. <td class="forminp">
  569. <select multiple="multiple" name="<?php echo esc_attr( $value['id'] ); ?>[]" style="width:450px;" data-placeholder="<?php _e( 'Choose countries&hellip;', 'woocommerce' ); ?>" title="Country" class="chosen_select">
  570. <?php
  571. if ($countries) foreach ($countries as $key=>$val) :
  572. echo '<option value="'.$key.'" '.selected( in_array($key, $selections), true, false ).'>'.$val.'</option>';
  573. endforeach;
  574. ?>
  575. </select>
  576. </td>
  577. </tr><?php
  578. break;
  579. default:
  580. do_action( 'woocommerce_admin_field_' . $value['type'], $value );
  581. break;
  582. }
  583. }
  584. }