Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. <?php
  2.  
  3. class WC_Settings_Tab_Demo {
  4. /**
  5. * Bootstraps the class and hooks required actions & filters.
  6. *
  7. */
  8. public static function init() {
  9. add_filter( 'woocommerce_settings_tabs_array', __CLASS__ . '::add_settings_tab', 50 );
  10. add_action( 'woocommerce_settings_tabs_settings_tab_demo', __CLASS__ . '::settings_tab' );
  11. add_action( 'woocommerce_update_options_settings_tab_demo', __CLASS__ . '::update_settings' );
  12. }
  13.  
  14.  
  15. /**
  16. * Add a new settings tab to the WooCommerce settings tabs array.
  17. *
  18. * @param array $settings_tabs Array of WooCommerce setting tabs & their labels, excluding the Subscription tab.
  19. * @return array $settings_tabs Array of WooCommerce setting tabs & their labels, including the Subscription tab.
  20. */
  21. public static function add_settings_tab( $settings_tabs ) {
  22. $settings_tabs['settings_tab_demo'] = __( 'Settings Demo Tab', 'woocommerce-settings-tab-demo' );
  23. return $settings_tabs;
  24. }
  25. /**
  26. * Uses the WooCommerce admin fields API to output settings via the @see woocommerce_admin_fields() function.
  27. *
  28. * @uses woocommerce_admin_fields()
  29. * @uses self::get_settings()
  30. */
  31. public static function settings_tab() {
  32. woocommerce_admin_fields( self::get_settings() );
  33. }
  34. /**
  35. * Uses the WooCommerce options API to save settings via the @see woocommerce_update_options() function.
  36. *
  37. * @uses woocommerce_update_options()
  38. * @uses self::get_settings()
  39. */
  40. public static function update_settings() {
  41. woocommerce_update_options( self::get_settings() );
  42. }
  43. /**
  44. * Get all the settings for this plugin for @see woocommerce_admin_fields() function.
  45. *
  46. * @return array Array of settings for @see woocommerce_admin_fields() function.
  47. */
  48. public static function get_settings() {
  49. $settings = array(
  50. 'section_title' => array(
  51. 'name' => __( 'Section Title', 'woocommerce-settings-tab-demo' ),
  52. 'type' => 'title',
  53. 'desc' => '',
  54. 'id' => 'wc_settings_tab_demo_section_title'
  55. ),
  56. 'title' => array(
  57. 'name' => __( 'Title', 'woocommerce-settings-tab-demo' ),
  58. 'type' => 'text',
  59. 'desc' => __( 'This is some helper text', 'woocommerce-settings-tab-demo' ),
  60. 'id' => 'wc_settings_tab_demo_title'
  61. ),
  62. 'description' => array(
  63. 'name' => __( 'Description', 'woocommerce-settings-tab-demo' ),
  64. 'type' => 'textarea',
  65. 'desc' => __( 'This is a paragraph describing the setting. Lorem ipsum yadda yadda yadda. Lorem ipsum yadda yadda yadda. Lorem ipsum yadda yadda yadda. Lorem ipsum yadda yadda yadda.', 'woocommerce-settings-tab-demo' ),
  66. 'id' => 'wc_settings_tab_demo_description'
  67. ),
  68. 'section_end' => array(
  69. 'type' => 'sectionend',
  70. 'id' => 'wc_settings_tab_demo_section_end'
  71. )
  72. );
  73. return apply_filters( 'wc_settings_tab_demo_settings', $settings );
  74. }
  75. }
  76. WC_Settings_Tab_Demo::init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement