WPSEO_Metabox_Form_Tab

Generates the HTML for a metabox tab.

Defined (1)

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

/admin/metabox/class-metabox-form-tab.php  
  1. class WPSEO_Metabox_Form_Tab implements WPSEO_Metabox_Tab { 
  2.  
  3. /** 
  4. * @var string 
  5. */ 
  6. private $name; 
  7.  
  8. /** 
  9. * @var string 
  10. */ 
  11. private $content; 
  12.  
  13. /** 
  14. * @var string 
  15. */ 
  16. private $link_content; 
  17.  
  18. /** 
  19. * @var string 
  20. */ 
  21. private $tab_class; 
  22.  
  23. /** 
  24. * @var string 
  25. */ 
  26. private $link_class; 
  27.  
  28. /** 
  29. * @var string 
  30. */ 
  31. private $link_title; 
  32.  
  33. /** 
  34. * @var string 
  35. */ 
  36. private $link_aria_label; 
  37.  
  38. /** 
  39. * @var boolean 
  40. */ 
  41. private $single; 
  42.  
  43. /** 
  44. * Constructor. 
  45. * @param string $name The name of the tab, used as an identifier in the html. 
  46. * @param string $content The tab content. 
  47. * @param string $link_content The text content of the tab link. 
  48. * @param array $options Optional link attributes. 
  49. */ 
  50. public function __construct( $name, $content, $link_content, array $options = array() ) { 
  51. $default_options = array( 
  52. 'tab_class' => '',  
  53. 'link_class' => '',  
  54. 'link_title' => '',  
  55. 'link_aria_label' => '',  
  56. 'single' => false,  
  57. ); 
  58. $options = array_merge( $default_options, $options ); 
  59.  
  60. $this->name = $name; 
  61. $this->content = $content; 
  62. $this->link_content = $link_content; 
  63. $this->tab_class = $options['tab_class']; 
  64. $this->link_class = $options['link_class']; 
  65. $this->link_title = $options['link_title']; 
  66. $this->link_aria_label = $options['link_aria_label']; 
  67. $this->single = $options['single']; 
  68.  
  69. /** 
  70. * Returns the html for the tab link. 
  71. * @return string 
  72. */ 
  73. public function link() { 
  74.  
  75. $html = '<li class="%1$s%2$s"><a class="wpseo_tablink%3$s" href="#wpseo_%1$s"%4$s%5$s>%6$s</a></li>'; 
  76.  
  77. if ( $this->single ) { 
  78. $html = '<li class="%1$s%2$s"><span class="wpseo_tablink%3$s"%4$s%5$s>%6$s</span></li>'; 
  79.  
  80. return sprintf( 
  81. $html,  
  82. esc_attr( $this->name ),  
  83. ( '' !== $this->tab_class ) ? ' ' . esc_attr( $this->tab_class ) : '',  
  84. ( '' !== $this->link_class ) ? ' ' . esc_attr( $this->link_class ) : '',  
  85. ( '' !== $this->link_title ) ? ' title="' . esc_attr( $this->link_title ) . '"' : '',  
  86. ( '' !== $this->link_aria_label ) ? ' aria-label="' . esc_attr( $this->link_aria_label ) . '"' : '',  
  87. $this->link_content 
  88. ); 
  89.  
  90. /** 
  91. * Returns the html for the tab content. 
  92. * @return string 
  93. */ 
  94. public function content() { 
  95. return sprintf( 
  96. '<div id="wpseo_%1$s" class="wpseotab %1$s">%2$s</div>',  
  97. esc_attr( $this->name ),  
  98. $this->content 
  99. );