WCBulkOrderForm_Settings_Standard_Template

The WooCommerce Bulk Order Form WCBulkOrderForm Settings Standard Template class.

Defined (1)

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

/includes/templates/standard_template/standard_template_options.php  
  1. class WCBulkOrderForm_Settings_Standard_Template { 
  2.  
  3. public function __construct() { 
  4. add_action( 'admin_init', array( &$this, 'init_settings' ) ); // Registers settings 
  5. add_action('wcbulkorderform_settings', array(&$this, 'print_settings')); 
  6.  
  7. /** 
  8. * Print Settings 
  9. */ 
  10. public function print_settings() { 
  11. settings_fields( 'wcbulkorderform_standard_template' ); 
  12. do_settings_sections( 'wcbulkorderform_standard_template' ); 
  13. $option = get_option('wcbulkorderform_standard_template'); 
  14. //print_r($option); 
  15.  
  16. /** 
  17. * User settings. 
  18. */ 
  19. public function init_settings() { 
  20.  
  21. $option = 'wcbulkorderform_standard_template'; 
  22.  
  23. // Create option in wp_options. 
  24. if ( false == get_option( $option ) ) { 
  25. add_option( $option ); 
  26.  
  27. // Section. 
  28. add_settings_section( 
  29. 'plugin_settings',  
  30. __( 'Plugin Settings', 'wcbulkorderform' ),  
  31. array( &$this, 'section_options_callback' ),  
  32. $option 
  33. ); 
  34.  
  35. add_settings_field( 
  36. 'search_by',  
  37. __( 'When searching for products search by:', 'wcbulkorderform' ),  
  38. array( &$this, 'radio_element_callback' ),  
  39. $option,  
  40. 'plugin_settings',  
  41. array( 
  42. 'menu' => $option,  
  43. 'id' => 'search_by',  
  44. 'options' => array( 
  45. '1' => __( 'SKU' , 'wcbulkorderform' ),  
  46. '2' => __( 'ID' , 'wcbulkorderform' ),  
  47. '3' => __( 'Title' , 'wcbulkorderform' ),  
  48. '4' => __( 'All' , 'wcbulkorderform' ) 
  49. ),  
  50. 'disabled' => true,  
  51. 'default' => '4' 
  52. ); 
  53.  
  54. add_settings_field( 
  55. 'attribute_style',  
  56. __( 'Display attribute title or just attribute value? Ex. (Color: Red) or (Red)', 'wcbulkorderform' ),  
  57. array( &$this, 'radio_element_callback' ),  
  58. $option,  
  59. 'plugin_settings',  
  60. array( 
  61. 'menu' => $option,  
  62. 'id' => 'attribute_style',  
  63. 'options' => array( 
  64. 'true' => __( 'Attribute value only (recommended)' , 'wcbulkorderform' ),  
  65. 'false' => __( 'Attribute title and value' , 'wcbulkorderform' ) 
  66. ),  
  67. 'default' => 'false' 
  68. ); 
  69.  
  70. add_settings_field( 
  71. 'search_format',  
  72. __( 'Choose your product search results format', 'wcbulkorderform' ),  
  73. array( &$this, 'radio_element_callback' ),  
  74. $option,  
  75. 'plugin_settings',  
  76. array( 
  77. 'menu' => $option,  
  78. 'id' => 'search_format',  
  79. 'options' => array( 
  80. '1' => __( 'SKU - Title - Price' , 'wcbulkorderform' ),  
  81. '2' => __( 'Title - Price - SKU' , 'wcbulkorderform' ),  
  82. '3' => __( 'Title - Price' , 'wcbulkorderform' ),  
  83. '4' => __( 'Title - SKU' , 'wcbulkorderform' ),  
  84. '5' => __( 'Title' , 'wcbulkorderform' ) 
  85. ),  
  86. 'disabled' => true,  
  87. 'default' => '2' 
  88. ); 
  89.  
  90. add_settings_field( 
  91. 'new_row_button',  
  92. __( 'Display "Add New Row" Button?', 'wcbulkorderform' ),  
  93. array( &$this, 'radio_element_callback' ),  
  94. $option,  
  95. 'plugin_settings',  
  96. array( 
  97. 'menu' => $option,  
  98. 'id' => 'new_row_button',  
  99. 'options' => array( 
  100. 'true' => __( 'Yes' , 'wcbulkorderform' ),  
  101. 'false' => __( 'No' , 'wcbulkorderform' ) 
  102. ),  
  103. 'disabled' => true,  
  104. 'default' => 'false' 
  105. ); 
  106.  
  107. add_settings_field( 
  108. 'display_images',  
  109. __( 'Display product images in autocomplete search?', 'wcbulkorderform' ),  
  110. array( &$this, 'radio_element_callback' ),  
  111. $option,  
  112. 'plugin_settings',  
  113. array( 
  114. 'menu' => $option,  
  115. 'id' => 'display_images',  
  116. 'options' => array( 
  117. 'true' => __( 'Yes' , 'wcbulkorderform' ),  
  118. 'false' => __( 'No' , 'wcbulkorderform' ) 
  119. ),  
  120. 'disabled' => true,  
  121. 'default' => 'false' 
  122. ); 
  123.  
  124. // Section. 
  125. add_settings_section( 
  126. 'advanced_settings',  
  127. __( 'Default Shortcode Options', 'wcbulkorderform' ),  
  128. array( &$this, 'section_options_callback' ),  
  129. $option 
  130. ); 
  131.  
  132. add_settings_field( 
  133. 'bulkorder_row_number',  
  134. __( 'Number of rows to display on the bulk order form', 'wcbulkorderform' ),  
  135. array( &$this, 'text_element_callback' ),  
  136. $option,  
  137. 'advanced_settings',  
  138. array( 
  139. 'menu' => $option,  
  140. 'id' => 'bulkorder_row_number' 
  141. ); 
  142.  
  143. add_settings_field( 
  144. 'max_items',  
  145. __( 'Maximum Items to Display in a Search', 'wcbulkorderform' ),  
  146. array( &$this, 'text_element_callback' ),  
  147. $option,  
  148. 'advanced_settings',  
  149. array( 
  150. 'menu' => $option,  
  151. 'id' => 'max_items' 
  152. ); 
  153.  
  154. add_settings_field( 
  155. 'display_price',  
  156. __( 'Display price on bulk order form?', 'wcbulkorderform' ),  
  157. array( &$this, 'radio_element_callback' ),  
  158. $option,  
  159. 'advanced_settings',  
  160. array( 
  161. 'menu' => $option,  
  162. 'id' => 'display_price',  
  163. 'options' => array( 
  164. 'true' => __( 'Yes' , 'wcbulkorderform' ),  
  165. 'false' => __( 'No' , 'wcbulkorderform' ) 
  166. ),  
  167. ); 
  168.  
  169. add_settings_field( 
  170. 'product_field_title',  
  171. __( 'Title for product fields', 'wcbulkorderform' ),  
  172. array( &$this, 'text_element_callback' ),  
  173. $option,  
  174. 'advanced_settings',  
  175. array( 
  176. 'menu' => $option,  
  177. 'id' => 'product_field_title' 
  178. ); 
  179.  
  180. add_settings_field( 
  181. 'quantity_field_title',  
  182. __( 'Title for quantity fields', 'wcbulkorderform' ),  
  183. array( &$this, 'text_element_callback' ),  
  184. $option,  
  185. 'advanced_settings',  
  186. array( 
  187. 'menu' => $option,  
  188. 'id' => 'quantity_field_title' 
  189. ); 
  190.  
  191. add_settings_field( 
  192. 'price_field_title',  
  193. __( 'Title for price fields', 'wcbulkorderform' ),  
  194. array( &$this, 'text_element_callback' ),  
  195. $option,  
  196. 'advanced_settings',  
  197. array( 
  198. 'menu' => $option,  
  199. 'id' => 'price_field_title' 
  200. ); 
  201.  
  202. add_settings_field( 
  203. 'no_load_css',  
  204. __( "Don't load jquery ui styles. (Don't check this unless you know your site is loading jquery ui styles from another source)", 'wpmenucart' ),  
  205. array( &$this, 'checkbox_element_callback' ),  
  206. $option,  
  207. 'plugin_settings',  
  208. array( 
  209. 'menu' => $option,  
  210. 'id' => 'no_load_css',  
  211. ); 
  212.  
  213. // Register settings. 
  214. register_setting( $option, $option, array( &$this, 'wcbulkorderform_options_validate' ) ); 
  215.  
  216. // Register defaults if settings empty (might not work in case there's only checkboxes and they're all disabled) 
  217. $option_values = get_option($option); 
  218. if ( empty( $option_values ) ) { 
  219. $this->default_settings(); 
  220.  
  221. /** 
  222. * Add settings link to plugins page 
  223. */ 
  224. public function wcbulkorderform_add_settings_link( $links ) { 
  225. $settings_link = '<a href="options-general.php?page=wcbulkorderform_options_page">'. __( 'Settings', 'woocommerce' ) . '</a>'; 
  226. array_push( $links, $settings_link ); 
  227. return $links; 
  228.  
  229. /** 
  230. * Default settings. 
  231. */ 
  232. public function default_settings() { 
  233. global $options; 
  234. $default = array( 
  235. 'search_by' => '4',  
  236. 'search_format' => '2',  
  237. 'new_row_button' => 'false',  
  238. 'bulkorder_row_number' => '5',  
  239. 'max_items' => '20',  
  240. 'display_price' => 'true',  
  241. 'product_field_title' => 'Product',  
  242. 'quantity_field_title' => 'Quantity',  
  243. 'price_field_title' => 'Price',  
  244. 'no_load_css' => '',  
  245. 'display_images' => 'false',  
  246. 'attribute_style' => 'true' 
  247. ); 
  248.  
  249. update_option( 'wcbulkorderform_standard_template', $default ); 
  250.  
  251. /** 
  252. * Build the options page. 
  253. */ 
  254. public function wcbulkorderform_options_do_page() {  
  255. ?> 
  256.  
  257. <div class="wrap"> 
  258. <div class="icon32" id="icon-options-general"><br /></div> 
  259. <h2><?php _e('WC Bulk Order Form Pro', 'wcbulkorderform') ?></h2> 
  260. <?php  
  261. global $options; 
  262. $sections = get_option('wcbulkorderform_sections'); 
  263. //print_r($sections); 
  264. //$option = get_option('wcbulkorderform'); 
  265. //print_r($option); //for debugging 
  266. ?> 
  267. <form method="post" action="options.php"> 
  268. <?php 
  269. //delete_option('wcbulkorderform');  
  270. settings_fields( 'wcbulkorderform' ); 
  271. do_settings_sections( 'wcbulkorderform' ); 
  272.  
  273. submit_button(); 
  274. ?> 
  275.  
  276. </form> 
  277. </div> 
  278. <?php 
  279.  
  280. /** 
  281. * Text field callback. 
  282. * @param array $args Field arguments. 
  283. * @return string Text field. 
  284. */ 
  285. public function text_element_callback( $args ) { 
  286. $menu = $args['menu']; 
  287. $id = $args['id']; 
  288. $size = isset( $args['size'] ) ? $args['size'] : '25'; 
  289.  
  290. $options = get_option( $menu ); 
  291.  
  292. if ( isset( $options[$id] ) ) { 
  293. $current = $options[$id]; 
  294. } else { 
  295. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  296.  
  297. $disabled = (isset( $args['disabled'] )) ? ' disabled' : ''; 
  298. $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 ); 
  299.  
  300. // Displays option description. 
  301. if ( isset( $args['description'] ) ) { 
  302. $html .= sprintf( '<p class="description">%s</p>', $args['description'] ); 
  303.  
  304. echo $html; 
  305.  
  306. /** 
  307. * Displays a selectbox for a settings field 
  308. * @param array $args settings field args 
  309. */ 
  310. public function select_element_callback( $args ) { 
  311. $menu = $args['menu']; 
  312. $id = $args['id']; 
  313.  
  314. $options = get_option( $menu ); 
  315.  
  316. if ( isset( $options[$id] ) ) { 
  317. $current = $options[$id]; 
  318. } else { 
  319. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  320.  
  321. $disabled = (isset( $args['disabled'] )) ? ' disabled' : ''; 
  322.  
  323. $html = sprintf( '<select name="%1$s[%2$s]" id="%1$s[%2$s]"%3$s>', $menu, $id, $disabled ); 
  324. $html .= sprintf( '<option value="%s"%s>%s</option>', '0', selected( $current, '0', false ), '' ); 
  325.  
  326. foreach ( $args['options'] as $key => $label ) { 
  327. $html .= sprintf( '<option value="%s"%s>%s</option>', $key, selected( $current, $key, false ), $label ); 
  328. $html .= sprintf( '</select>' ); 
  329.  
  330. if ( isset( $args['description'] ) ) { 
  331. $html .= sprintf( '<p class="description">%s</p>', $args['description'] ); 
  332.  
  333. echo $html; 
  334.  
  335. /** 
  336. * Displays a multiple selectbox for a settings field 
  337. * @param array $args settings field args 
  338. */ 
  339. public function multiple_select_element_callback( $args ) { 
  340. $html = ''; 
  341. foreach ($args as $id => $boxes) { 
  342. $menu = $boxes['menu']; 
  343.  
  344. $options = get_option( $menu ); 
  345.  
  346. if ( isset( $options[$id] ) ) { 
  347. $current = $options[$id]; 
  348. } else { 
  349. $current = isset( $boxes['default'] ) ? $boxes['default'] : ''; 
  350.  
  351. $disabled = (isset( $boxes['disabled'] )) ? ' disabled' : ''; 
  352.  
  353. $html .= sprintf( '<select name="%1$s[%2$s]" id="%1$s[%2$s]"%3$s>', $menu, $id, $disabled); 
  354. $html .= sprintf( '<option value="%s"%s>%s</option>', '0', selected( $current, '0', false ), '' ); 
  355.  
  356. foreach ( (array) $boxes['options'] as $key => $label ) { 
  357. $html .= sprintf( '<option value="%s"%s>%s</option>', $key, selected( $current, $key, false ), $label ); 
  358. $html .= '</select>'; 
  359.  
  360. if ( isset( $boxes['description'] ) ) { 
  361. $html .= sprintf( '<p class="description">%s</p>', $boxes['description'] ); 
  362. $html .= '<br />'; 
  363.  
  364.  
  365. echo $html; 
  366.  
  367. /** 
  368. * Checkbox field callback. 
  369. * @param array $args Field arguments. 
  370. * @return string Checkbox field. 
  371. */ 
  372. public function checkbox_element_callback( $args ) { 
  373. $menu = $args['menu']; 
  374. $id = $args['id']; 
  375.  
  376. $options = get_option( $menu ); 
  377.  
  378. if ( isset( $options[$id] ) ) { 
  379. $current = $options[$id]; 
  380. } else { 
  381. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  382.  
  383. $disabled = (isset( $args['disabled'] )) ? ' disabled' : ''; 
  384. $html = sprintf( '<input type="checkbox" id="%1$s" name="%2$s[%1$s]" value="1"%3$s %4$s/>', $id, $menu, checked( 1, $current, false ), $disabled ); 
  385.  
  386. // Displays option description. 
  387. if ( isset( $args['description'] ) ) { 
  388. $html .= sprintf( '<p class="description">%s</p>', $args['description'] ); 
  389.  
  390. echo $html; 
  391.  
  392. /** 
  393. * Displays a multicheckbox a settings field 
  394. * @param array $args settings field args 
  395. */ 
  396. public function radio_element_callback( $args ) { 
  397. $menu = $args['menu']; 
  398. $id = $args['id']; 
  399.  
  400. $options = get_option( $menu ); 
  401.  
  402. if ( isset( $options[$id] ) ) { 
  403. $current = $options[$id]; 
  404. } else { 
  405. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  406.  
  407. $html = ''; 
  408. $class = 'radio'; 
  409. if (isset( $args['disabled'] )) { 
  410. $class .= ' wcbulkorder-disabled'; 
  411. foreach ( $args['options'] as $key => $label ) { 
  412. $html .= sprintf( '<input type="radio" class="%5$s" id="%1$s[%2$s][%3$s]" name="%1$s[%2$s]" value="%3$s"%4$s />', $menu, $id, $key, checked( $current, $key, false ), $class ); 
  413. $html .= sprintf( '<label for="%1$s[%2$s][%3$s]"> %4$s</label><br>', $menu, $id, $key, $label); 
  414.  
  415. // Displays option description. 
  416. if ( isset( $args['description'] ) ) { 
  417. $html .= sprintf( '<p class="description">%s</p>', $args['description'] ); 
  418.  
  419. if (isset( $args['disabled'] )) { 
  420. $html .= ' <span style="display:none;" class="pro-feature"><i>'. __('This feature only available in', 'wcbulkorderform') .' <a href="https://wpovernight.com/downloads/woocommerce-bulk-order-form/?utm_source=wordpress&utm_medium=wcbulkorderformfree&utm_campaign=bulkorderformfree">Bulk Order Form Pro</a></i></span>'; 
  421. $html .= '<div style="position:absolute; left:0; right:0; top:0; bottom:0; background-color:white; -moz-opacity: 0; opacity:0;filter: alpha(opacity=0);" class="hidden-input"></div>'; 
  422. $html = '<div style="display:inline-block; position:relative;">'.$html.'</div>'; 
  423.  
  424. echo $html; 
  425.  
  426. /** 
  427. * Displays a multicheckbox a settings field 
  428. * @param array $args settings field args 
  429. */ 
  430. public function icons_radio_element_callback( $args ) { 
  431. $menu = $args['menu']; 
  432. $id = $args['id']; 
  433.  
  434. $options = get_option( $menu ); 
  435.  
  436. if ( isset( $options[$id] ) ) { 
  437. $current = $options[$id]; 
  438. } else { 
  439. $current = isset( $args['default'] ) ? $args['default'] : ''; 
  440.  
  441. $icons = ''; 
  442. $radios = ''; 
  443.  
  444. foreach ( $args['options'] as $key => $iconnumber ) { 
  445. $icons .= sprintf( '<td style="padding-bottom:0;font-size:16pt;" align="center"><label for="%1$s[%2$s][%3$s]"><i class="wcbulkorderform-icon-shopping-cart-%4$s"></i></label></td>', $menu, $id, $key, $iconnumber); 
  446. $radios .= sprintf( '<td style="padding-top:0" align="center"><input type="radio" class="radio" id="%1$s[%2$s][%3$s]" name="%1$s[%2$s]" value="%3$s"%4$s /></td>', $menu, $id, $key, checked( $current, $key, false ) ); 
  447.  
  448. $html = '<table><tr>'.$icons.'</tr><tr>'.$radios.'</tr></table>'; 
  449. $html .= '<p class="description"><i>'. __('<strong>Please note:</strong> you need to open your website in a new tab/browser window after updating the cart icon for the change to be visible!', 'wcbulkorderform').'</p>'; 
  450.  
  451. echo $html; 
  452.  
  453. /** 
  454. * Section null callback. 
  455. * @return void. 
  456. */ 
  457. public function section_options_callback() { 
  458.  
  459.  
  460. /** 
  461. * Validate/sanitize options input 
  462. */ 
  463. public function wcbulkorderform_options_validate( $input ) { 
  464. // Create our array for storing the validated options. 
  465. $output = array(); 
  466.  
  467. // Loop through each of the incoming options. 
  468. foreach ( $input as $key => $value ) { 
  469.  
  470. // Check to see if the current option has a value. If so, process it. 
  471. if ( isset( $input[$key] ) ) { 
  472.  
  473. // Strip all HTML and PHP tags and properly handle quoted strings. 
  474. $output[$key] = strip_tags( stripslashes( $input[$key] ) ); 
  475.  
  476. // Return the array processing any additional functions filtered by this action. 
  477. return apply_filters( 'wcbulkorderform_validate_input', $output, $input ); 
  478.