/includes/templates/standard_template/standard_template_options.php

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