class-metabox-tab-section.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin
  6. */
  7. /**
  8. * Generates and displays the HTML for a metabox section.
  9. */
  10. class WPSEO_Metabox_Tab_Section extends WPSEO_Abstract_Metabox_Tab_With_Sections {
  11. /**
  12. * An instance of the Metabox Tab class.
  13. *
  14. * @var WPSEO_Metabox_Tab[]
  15. */
  16. public $tabs = array();
  17. /**
  18. * Constructor.
  19. *
  20. * @deprecated 12.3
  21. * @codeCoverageIgnore
  22. *
  23. * @param string $name The name of the section, used as an identifier in the html.
  24. * Can only contain URL safe characters.
  25. * @param string $link_content The text content of the section link.
  26. * @param array $tabs The metabox tabs (`WPSEO_Metabox_Tabs[]`) to be included in the section.
  27. * @param array $options Optional link attributes.
  28. */
  29. public function __construct( $name, $link_content, array $tabs = array(), array $options = array() ) {
  30. _deprecated_function( __METHOD__, 'WPSEO 12.3' );
  31. parent::__construct( $name, $link_content, $options );
  32. // Filter out invalid tab instances.
  33. $valid_tabs = array_filter( $tabs, array( $this, 'is_valid_tab' ) );
  34. foreach ( $valid_tabs as $tab ) {
  35. $this->add_tab( $tab );
  36. }
  37. }
  38. /**
  39. * Determines whether the passed tab is considered valid.
  40. *
  41. * @deprecated 12.3
  42. * @codeCoverageIgnore
  43. *
  44. * @param mixed $tab The potential tab that needs to be validated.
  45. *
  46. * @return bool Whether or not the tab is valid.
  47. */
  48. protected function is_valid_tab( $tab ) {
  49. _deprecated_function( __METHOD__, 'WPSEO 12.3' );
  50. if ( $tab instanceof WPSEO_Metabox_Tab && ! $tab instanceof WPSEO_Metabox_Null_Tab ) {
  51. return true;
  52. }
  53. return false;
  54. }
  55. /**
  56. * Outputs the section content if any tab has been added.
  57. *
  58. * @deprecated 12.3
  59. * @codeCoverageIgnore
  60. */
  61. public function display_content() {
  62. _deprecated_function( __METHOD__, 'WPSEO 12.3' );
  63. if ( $this->has_sections() ) {
  64. $html = '<div role="tabpanel" id="wpseo-meta-section-%1$s" aria-labelledby="wpseo-meta-tab-%1$s" tabindex="0" class="wpseo-meta-section">';
  65. $html .= '<div class="wpseo-metabox-tabs-div">';
  66. $html .= '<ul class="wpseo-metabox-tabs %2$s">%3$s</ul>%4$s';
  67. $html .= '</div></div>';
  68. printf(
  69. // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: This is deprecated.
  70. $html,
  71. esc_attr( $this->name ),
  72. esc_attr( 'wpseo-metabox-tab-' . $this->name ),
  73. // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: This is deprecated.
  74. $this->tab_links(),
  75. // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: This is deprecated.
  76. $this->tab_content()
  77. );
  78. }
  79. }
  80. /**
  81. * Add a `WPSEO_Metabox_Tab` object to the tabs.
  82. *
  83. * @deprecated 12.3
  84. * @codeCoverageIgnore
  85. *
  86. * @param WPSEO_Metabox_Tab $tab Tab to add.
  87. */
  88. public function add_tab( WPSEO_Metabox_Tab $tab ) {
  89. _deprecated_function( __METHOD__, 'WPSEO 12.3' );
  90. $this->tabs[] = $tab;
  91. }
  92. /**
  93. * Checks if any tabs have been added to the section.
  94. *
  95. * @deprecated 12.3
  96. * @codeCoverageIgnore
  97. *
  98. * @return bool
  99. */
  100. protected function has_sections() {
  101. _deprecated_function( __METHOD__, 'WPSEO 12.3' );
  102. return ! empty( $this->tabs );
  103. }
  104. /**
  105. * Concatenates all tabs' links into one html string.
  106. *
  107. * @deprecated 12.3
  108. * @codeCoverageIgnore
  109. *
  110. * @return string
  111. */
  112. private function tab_links() {
  113. _deprecated_function( __METHOD__, 'WPSEO 12.3' );
  114. $links = '';
  115. foreach ( $this->tabs as $tab ) {
  116. $links .= $tab->link();
  117. }
  118. return $links;
  119. }
  120. /**
  121. * Concatenates all tabs' content into one html string.
  122. *
  123. * @deprecated 12.3
  124. * @codeCoverageIgnore
  125. *
  126. * @return string
  127. */
  128. private function tab_content() {
  129. _deprecated_function( __METHOD__, 'WPSEO 12.3' );
  130. $content = '';
  131. foreach ( $this->tabs as $tab ) {
  132. $content .= $tab->content();
  133. }
  134. return $content;
  135. }
  136. /**
  137. * Gets the name of the tab section.
  138. *
  139. * @deprecated 12.3
  140. * @codeCoverageIgnore
  141. *
  142. * @return string The name of the tab section.
  143. */
  144. public function get_name() {
  145. _deprecated_function( __METHOD__, 'WPSEO 12.3' );
  146. return $this->name;
  147. }
  148. }