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