WPSEO_Option_Tabs

Class WPSEO_Option_Tabs.

Defined (1)

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

/admin/class-option-tabs.php  
  1. class WPSEO_Option_Tabs { 
  2.  
  3. /** @var string Tabs base */ 
  4. private $base; 
  5.  
  6. /** @var array The tabs in this group */ 
  7. private $tabs = array(); 
  8.  
  9. /** @var string Name of the active tab */ 
  10. private $active_tab = ''; 
  11.  
  12. /** 
  13. * WPSEO_Option_Tabs constructor. 
  14. * @param string $base Base of the tabs. 
  15. * @param string $active_tab Currently active tab. 
  16. */ 
  17. public function __construct( $base, $active_tab = '' ) { 
  18. $this->base = sanitize_title( $base ); 
  19.  
  20. $tab = filter_input( INPUT_GET, 'tab' ); 
  21. $this->active_tab = empty( $tab ) ? $active_tab : $tab; 
  22.  
  23. /** 
  24. * Get the base 
  25. * @return string 
  26. */ 
  27. public function get_base() { 
  28. return $this->base; 
  29.  
  30. /** 
  31. * Add a tab 
  32. * @param WPSEO_Option_Tab $tab Tab to add. 
  33. * @return $this 
  34. */ 
  35. public function add_tab( WPSEO_Option_Tab $tab ) { 
  36. $this->tabs[] = $tab; 
  37.  
  38. return $this; 
  39.  
  40. /** 
  41. * Get active tab 
  42. * @return null|WPSEO_Option_Tab Get the active tab. 
  43. */ 
  44. public function get_active_tab() { 
  45. if ( empty( $this->active_tab ) ) { 
  46. return null; 
  47.  
  48. $active_tabs = array_filter( $this->tabs, array( $this, 'is_active_tab' ) ); 
  49. if ( ! empty( $active_tabs ) ) { 
  50. $active_tabs = array_values( $active_tabs ); 
  51. if ( count( $active_tabs ) === 1 ) { 
  52. return $active_tabs[0]; 
  53.  
  54. return null; 
  55.  
  56. /** 
  57. * Is the tab the active tab 
  58. * @param WPSEO_Option_Tab $tab Tab to check for active tab. 
  59. * @return bool 
  60. */ 
  61. public function is_active_tab( WPSEO_Option_Tab $tab ) { 
  62. return ( $tab->get_name() === $this->active_tab ); 
  63.  
  64. /** 
  65. * Get all tabs 
  66. * @return WPSEO_Option_Tab[] 
  67. */ 
  68. public function get_tabs() { 
  69. return $this->tabs; 
  70.  
  71. /** 
  72. * Display the tabs 
  73. * @param Yoast_Form $yform Yoast Form needed in the views. 
  74. * @param array $options Options needed in the views. 
  75. */ 
  76. public function display( Yoast_Form $yform, $options = array() ) { 
  77. $formatter = new WPSEO_Option_Tabs_Formatter(); 
  78. $formatter->run( $this, $yform, $options );