WC_Settings_Page

WC_Settings_Page.

Defined (1)

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

/includes/admin/settings/class-wc-settings-page.php  
  1. abstract class WC_Settings_Page { 
  2.  
  3. /** 
  4. * Setting page id. 
  5. * @var string 
  6. */ 
  7. protected $id = ''; 
  8.  
  9. /** 
  10. * Setting page label. 
  11. * @var string 
  12. */ 
  13. protected $label = ''; 
  14.  
  15. /** 
  16. * Constructor. 
  17. */ 
  18. public function __construct() { 
  19. add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 ); 
  20. add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) ); 
  21. add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) ); 
  22. add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) ); 
  23.  
  24. /** 
  25. * Get settings page ID. 
  26. * @since 3.0.0 
  27. * @return string 
  28. */ 
  29. public function get_id() { 
  30. return $this->id; 
  31.  
  32. /** 
  33. * Get settings page label. 
  34. * @since 3.0.0 
  35. * @return string 
  36. */ 
  37. public function get_label() { 
  38. return $this->label; 
  39.  
  40. /** 
  41. * Add this page to settings. 
  42. */ 
  43. public function add_settings_page( $pages ) { 
  44. $pages[ $this->id ] = $this->label; 
  45.  
  46. return $pages; 
  47.  
  48. /** 
  49. * Get settings array. 
  50. * @return array 
  51. */ 
  52. public function get_settings() { 
  53. return apply_filters( 'woocommerce_get_settings_' . $this->id, array() ); 
  54.  
  55. /** 
  56. * Get sections. 
  57. * @return array 
  58. */ 
  59. public function get_sections() { 
  60. return apply_filters( 'woocommerce_get_sections_' . $this->id, array() ); 
  61.  
  62. /** 
  63. * Output sections. 
  64. */ 
  65. public function output_sections() { 
  66. global $current_section; 
  67.  
  68. $sections = $this->get_sections(); 
  69.  
  70. if ( empty( $sections ) || 1 === sizeof( $sections ) ) { 
  71. return; 
  72.  
  73. echo '<ul class="subsubsub">'; 
  74.  
  75. $array_keys = array_keys( $sections ); 
  76.  
  77. foreach ( $sections as $id => $label ) { 
  78. echo '<li><a href="' . admin_url( 'admin.php?page=wc-settings&tab=' . $this->id . '§ion=' . sanitize_title( $id ) ) . '" class="' . ( $current_section == $id ? 'current' : '' ) . '">' . $label . '</a> ' . ( end( $array_keys ) == $id ? '' : '|' ) . ' </li>'; 
  79.  
  80. echo '</ul><br class="clear" />'; 
  81.  
  82. /** 
  83. * Output the settings. 
  84. */ 
  85. public function output() { 
  86. $settings = $this->get_settings(); 
  87.  
  88. WC_Admin_Settings::output_fields( $settings ); 
  89.  
  90. /** 
  91. * Save settings. 
  92. */ 
  93. public function save() { 
  94. global $current_section; 
  95.  
  96. $settings = $this->get_settings(); 
  97. WC_Admin_Settings::save_fields( $settings ); 
  98.  
  99. if ( $current_section ) { 
  100. do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section );