class-option-tabs-formatter.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\Options\Tabs
  6. */
  7. /**
  8. * Class WPSEO_Option_Tabs_Formatter.
  9. */
  10. class WPSEO_Option_Tabs_Formatter {
  11. /**
  12. * Retrieves the path to the view of the tab.
  13. *
  14. * @param WPSEO_Option_Tabs $option_tabs Option Tabs to get base from.
  15. * @param WPSEO_Option_Tab $tab Tab to get name from.
  16. *
  17. * @return string
  18. */
  19. public function get_tab_view( WPSEO_Option_Tabs $option_tabs, WPSEO_Option_Tab $tab ) {
  20. return WPSEO_PATH . 'admin/views/tabs/' . $option_tabs->get_base() . '/' . $tab->get_name() . '.php';
  21. }
  22. /**
  23. * Outputs the option tabs.
  24. *
  25. * @param WPSEO_Option_Tabs $option_tabs Option Tabs to get tabs from.
  26. */
  27. public function run( WPSEO_Option_Tabs $option_tabs ) {
  28. echo '<h2 class="nav-tab-wrapper" id="wpseo-tabs">';
  29. foreach ( $option_tabs->get_tabs() as $tab ) {
  30. printf(
  31. '<a class="nav-tab" id="%1$s" href="%2$s">%3$s</a>',
  32. esc_attr( $tab->get_name() . '-tab' ),
  33. esc_url( '#top#' . $tab->get_name() ),
  34. esc_html( $tab->get_label() )
  35. );
  36. }
  37. echo '</h2>';
  38. foreach ( $option_tabs->get_tabs() as $tab ) {
  39. $identifier = $tab->get_name();
  40. $class = 'wpseotab ' . ( $tab->has_save_button() ? 'save' : 'nosave' );
  41. printf( '<div id="%1$s" class="%2$s">', esc_attr( $identifier ), esc_attr( $class ) );
  42. $tab_filter_name = sprintf( '%s_%s', $option_tabs->get_base(), $tab->get_name() );
  43. /**
  44. * Allows to override the content that is display on the specific option tab.
  45. *
  46. * @internal For internal Yoast SEO use only.
  47. *
  48. * @api string|null The content that should be displayed for this tab. Leave empty for default behaviour.
  49. *
  50. * @param WPSEO_Option_Tabs $option_tabs The registered option tabs.
  51. * @param WPSEO_Option_Tab $tab The tab that is being displayed.
  52. */
  53. $option_tab_content = apply_filters( 'wpseo_option_tab-' . $tab_filter_name, null, $option_tabs, $tab );
  54. if ( ! empty( $option_tab_content ) ) {
  55. echo wp_kses_post( $option_tab_content );
  56. }
  57. if ( empty( $option_tab_content ) ) {
  58. // Output the settings view for all tabs.
  59. $tab_view = $this->get_tab_view( $option_tabs, $tab );
  60. if ( is_file( $tab_view ) ) {
  61. $yform = Yoast_Form::get_instance();
  62. require $tab_view;
  63. }
  64. }
  65. echo '</div>';
  66. }
  67. }
  68. }