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