woocsv_import_settings

The Woocommerce CSV Import woocsv import settings class.

Defined (1)

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

/include/class-woocsv-import-settings.php  
  1. class woocsv_import_settings { 
  2.  
  3. public function __construct() { 
  4.  
  5. add_action( 'admin_init', array( $this, 'register_settings' )); 
  6.  
  7.  
  8. public function register_settings () { 
  9.  
  10. //woocsv import section 
  11. add_settings_section('woocsv-settings', '', array($this, 'section'), 'woocsv-settings'); 
  12.  
  13. //fields 
  14. //allowed roles 
  15. add_settings_field('woocsv_roles', __('Allowed Roles', 'woocommerce-csvimport'), array($this, 'roles'), 'woocsv-settings', 'woocsv-settings'); 
  16. register_setting( 'woocsv-settings', 'woocsv_roles', array($this, 'options_validate') ); 
  17.  
  18. //separator 
  19. add_settings_field('woocsv_separator', __('Field separator', 'woocommerce-csvimport'), array($this, 'separator'), 'woocsv-settings', 'woocsv-settings'); 
  20. register_setting( 'woocsv-settings', 'woocsv_separator', array($this, 'options_validate') ); 
  21.  
  22. //skip first row 
  23. add_settings_field('woocsv_skip_first_line', __('Skip the first row', 'woocommerce-csvimport'), array($this, 'skip_first_line'), 'woocsv-settings', 'woocsv-settings'); 
  24. register_setting( 'woocsv-settings', 'woocsv_skip_first_line', array($this, 'options_validate') ); 
  25.  
  26. //categories 
  27. add_settings_field('woocsv_add_to_categories', __('Add products to all categories', 'woocommerce-csvimport'), array($this, 'add_to_categories'), 'woocsv-settings', 'woocsv-settings'); 
  28. register_setting( 'woocsv-settings', 'woocsv_add_to_categories', array($this, 'options_validate') ); 
  29.  
  30. //blocksize 
  31. add_settings_field('woocsv_blocksize', __('Number of products to process simultaneously', 'woocommerce-csvimport'), array($this, 'blocksize'), 'woocsv-settings', 'woocsv-settings'); 
  32. register_setting( 'woocsv-settings', 'woocsv_blocksize', array($this, 'options_validate') ); 
  33.  
  34. //merge_products 
  35. add_settings_field('woocsv_merge_products', __('Merge products', 'woocommerce-csvimport'), array($this, 'merge_products'), 'woocsv-settings', 'woocsv-settings');  
  36. register_setting( 'woocsv-settings', 'woocsv_merge_products', array($this, 'options_validate') ); 
  37.  
  38. //debug 
  39. add_settings_field('woocsv_debug', __('Debug', 'woocommerce-csvimport'), array($this, 'debug'), 'woocsv-settings', 'woocsv-settings'); 
  40. register_setting( 'woocsv-settings', 'woocsv_debug', array($this, 'options_validate') ); 
  41.  
  42. //match_by 
  43. add_settings_field('woocsv_match_by', __('Find product using', 'woocommerce-csvimport'), array($this, 'match_by'), 'woocsv-settings', 'woocsv-settings'); 
  44. register_setting( 'woocsv-settings', 'woocsv_match_by', array($this, 'options_validate') ); 
  45.  
  46. //match_author_by 
  47. add_settings_field('woocsv_match_author_by', __('Match authors by', 'woocommerce-csvimport'), array($this, 'match_author_by'), 'woocsv-settings', 'woocsv-settings'); 
  48. register_setting( 'woocsv-settings', 'woocsv_match_author_by', array($this, 'options_validate') ); 
  49.  
  50. //convert to utf8 
  51. add_settings_field('woocsv_convert_to_utf8', __('Convert to UTF-08', 'woocommerce-csvimport'), array($this, 'convert_to_utf8'), 'woocsv-settings', 'woocsv-settings'); 
  52. register_setting( 'woocsv-settings', 'woocsv_convert_to_utf8', array($this, 'options_validate') ); 
  53.  
  54. //enable CURLOPT_FOLLOWLOCATION 
  55. add_settings_field('woocsv_curl_followlocation', __('Follow to location during image import', 'woocommerce-csvimport'), array($this, 'curl_followlocation'), 'woocsv-settings', 'woocsv-settings'); 
  56. register_setting( 'woocsv-settings', 'curl_followlocation', array($this, 'options_validate') ); 
  57.  
  58. function curl_followlocation () { 
  59. $value = get_option('woocsv_curl_followlocation'); 
  60. echo '<select id="woocsv_curl_followlocation" name="woocsv_curl_followlocation">'; 
  61. echo '<option '. selected("0", $value).' value="0">'.__('No', 'woocommerce-csvimport').'</option>'; 
  62. echo '<option '. selected("1", $value).' value="1">'.__('Yes', 'woocommerce-csvimport').'</option>'; 
  63. echo '</select>'; 
  64. echo '<p class="description">'.__('When you import images using an URL, the server sometimes redirects you to the actual path. This settings enabled that you follow that path. If you have safe_mode or open_basedir enabled, disable this setting.', 'woocommerce-csvimport').'</p>';  
  65.  
  66. public function match_author_by () { 
  67. $debug = get_option('woocsv_match_author_by'); 
  68. echo '<select id="match_author_by" name="woocsv_match_author_by">'; 
  69. echo '<option '. selected("id", $debug).' value="id">'.__('ID', 'woocommerce-csvimport').'</option>'; 
  70. echo '<option '. selected("slug", $debug).' value="slug">'.__('Slug', 'woocommerce-csvimport').'</option>'; 
  71. echo '<option '. selected("email", $debug).' value="email">'.__('Email', 'woocommerce-csvimport').'</option>'; 
  72. echo '<option '. selected("login", $debug).' value="login">'.__('Login', 'woocommerce-csvimport').'</option>'; 
  73. echo '</select>'; 
  74. echo '<p class="description">'.__('When you want the products to belong to a user you can select how the uses must be found. Using the ID, slug, email or login name of the user.', 'woocommerce-csvimport').'</p>';  
  75.  
  76. public function match_by () { 
  77. $debug = get_option('woocsv_match_by'); 
  78. echo '<select id="match_by" name="woocsv_match_by">'; 
  79. echo '<option '. selected("sku", $debug).' value="sku">'.__('Sku', 'woocommerce-csvimport').'</option>'; 
  80. echo '<option '. selected("title", $debug).' value="title">'.__('Title', 'woocommerce-csvimport').'</option>'; 
  81. echo '</select>'; 
  82. echo '<p class="description">'.__('When you merge products, products are found by there SKU, this is the unique identifier. In some cases, when you have no SKU, the post title could be used.', 'woocommerce-csvimport').'</p>';  
  83.  
  84. public function skip_first_line () { 
  85. $debug = get_option('woocsv_skip_first_line'); 
  86. echo '<select id="skip_first_line" name="woocsv_skip_first_line">'; 
  87. echo '<option '. selected("0", $debug).' value="0">'.__('No', 'woocommerce-csvimport').'</option>'; 
  88. echo '<option '. selected("1", $debug).' value="1">'.__('Yes', 'woocommerce-csvimport').'</option>'; 
  89. echo '</select>'; 
  90. echo '<p class="description">'.__('First lines in are often headers you do not want to import.', 'woocommerce-csvimport').'</p>';  
  91.  
  92.  
  93. public function debug () { 
  94. $debug = get_option('woocsv_debug'); 
  95. echo '<select id="debug" name="woocsv_debug">'; 
  96. echo '<option '. selected("0", $debug).' value="0">'.__('No', 'woocommerce-csvimport').'</option>'; 
  97. echo '<option '. selected("1", $debug).' value="1">'.__('Yes', 'woocommerce-csvimport').'</option>'; 
  98. echo '</select>'; 
  99. echo '<p class="description">'.__('When you enable debug, the javascript console will hold more information. IF you encounter problems the debug information may be useful in solving them.', 'woocommerce-csvimport').'</p>';  
  100.  
  101. public function merge_products () { 
  102. $merge_products = get_option('woocsv_merge_products'); 
  103. echo '<select id="woocsv_merge_products" name="woocsv_merge_products">'; 
  104. echo '<option '. selected("0", $merge_products).' value="0">'.__('No', 'woocommerce-csvimport').'</option>'; 
  105. echo '<option '. selected("1", $merge_products).' value="1">'.__('Yes', 'woocommerce-csvimport').'</option>'; 
  106. echo '</select>'; 
  107. echo '<p class="description">When you merge products, existing values of the product will be preserved. And only values from the CSV will be imported.</p>'; 
  108.  
  109. public function blocksize () { 
  110. $blocksize = get_option('woocsv_blocksize'); 
  111. echo '<select id="blocksize" name="woocsv_blocksize">'; 
  112. echo '<option '. selected("0", $blocksize).' value="0">'.__('auto', 'woocommerce-csvimport').'</option>'; 
  113. echo '<option '. selected("1", $blocksize).' value="1">'.__('1', 'woocommerce-csvimport').'</option>'; 
  114. echo '<option '. selected("10", $blocksize).' value="10">'.__('10', 'woocommerce-csvimport').'</option>'; 
  115. echo '<option '. selected("25", $blocksize).' value="25">'.__('25', 'woocommerce-csvimport').'</option>'; 
  116. echo '<option '. selected("50", $blocksize).' value="50">'.__('50', 'woocommerce-csvimport').'</option>'; 
  117. echo '<option '. selected("100", $blocksize).' value="100">'.__('100', 'woocommerce-csvimport').'</option>'; 
  118. echo '<option '. selected("10000", $blocksize).' value="10000">'.__('10000', 'woocommerce-csvimport').'</option>'; 
  119. echo '</select>'; 
  120. echo '<p class="description">'.__('The importing proces works with AJAX calls to avoid timeouts on large CSV files. With this setting you can influence how many rows there are processed every call.', 'woocommerce-csvimport').'</p>'; 
  121.  
  122. public function add_to_categories () { 
  123. $add_to_categories = get_option('woocsv_add_to_categories'); 
  124. echo '<select id="add_to_categories" name="woocsv_add_to_categories">'; 
  125. echo '<option '. selected("0", $add_to_categories).' value="0">'.__('No', 'woocommerce-csvimport').'</option>'; 
  126. echo '<option '. selected("1", $add_to_categories).' value="1">'.__('Yes', 'woocommerce-csvimport').'</option>'; 
  127. echo '</select>'; 
  128. echo '<p class="description">'.__('If you enable this, products will be added to all categories on not only the latest. Example :<code>cat1->subcat1</code> , if the option is enabled, the product belongs to both else it will only belong to the sub categorie.', 'woocommerce-csvimport').'</p>'; 
  129.  
  130.  
  131. public function separator() { 
  132. $separator = get_option('woocsv_separator'); 
  133. echo '<select id="woocsv_separator" name="woocsv_separator">'; 
  134. echo '<option '. selected(";", $separator).' value=";">;</option>'; 
  135. echo '<option '. selected(", ", $separator).' value=", ">, </option>'; 
  136. echo '<option '. selected("~", $separator).' value="~">~</option>'; 
  137. echo '</select>'; 
  138. echo '<p class="description">When you merge products, existing values of the product will be preserved. And only values from the CSV will be imported.</p>'; 
  139.  
  140. function roles() { 
  141. global $wp_roles, $woocsv_import; 
  142. $roles = (array)get_option('woocsv_roles'); 
  143. echo '<select size='.count($wp_roles->role_names).' id="woocsv_roles" name="woocsv_roles[]" multiple required>'; 
  144. foreach ($wp_roles->role_names as $key=>$value) { 
  145. echo "<option ".selected(true, in_array($key, $roles))." value=$key>$value</option>"; 
  146. echo '</select>'; 
  147. echo '<p class="description">'.__('These roles are allowed to import and change settings.', 'woocommerce-csvimport').'</p>'; 
  148.  
  149.  
  150. public function convert_to_utf8 () { 
  151. $value = get_option('woocsv_convert_to_utf8'); 
  152. echo '<select id="woocsv_convert_to_utf8" name="woocsv_convert_to_utf8">'; 
  153. echo '<option '. selected("0", $value).' value="0">'.__('No', 'woocommerce-csvimport').'</option>'; 
  154. echo '<option '. selected("1", $value).' value="1">'.__('utf08 encoding', 'woocommerce-csvimport').'</option>'; 
  155. echo '<option '. selected("2", $value).' value="2">'.__('mb-string conversion', 'woocommerce-csvimport').'</option>'; 
  156. echo '</select>'; 
  157. echo '<p class="description">'.__('Convert strings to UTF-08 during import?', 'woocommerce-csvimport').'</p>';  
  158.  
  159.  
  160. //! validation 
  161. function options_validate($input) { 
  162. //no validation yet 
  163. return $input; 
  164.  
  165. //sections callback 
  166. function section() { 
  167. //no text yet