Hide tabs with no content

This commit is contained in:
Brian Miyaji
2016-09-15 14:02:17 +10:00
parent c7c87cc4d1
commit 8a264e499b

View File

@@ -106,13 +106,12 @@ class SP_Template_Loader {
} }
$ob = ob_get_clean(); $ob = ob_get_clean();
ob_start();
$tabs = ''; $tabs = '';
if ( ! empty( $tab_templates ) ) { if ( ! empty( $tab_templates ) ) {
$i = 0; $i = 0;
$tab_content = '';
foreach ( $tab_templates as $key => $template ) { foreach ( $tab_templates as $key => $template ) {
// Ignore templates that are unavailable or that have been turned off // Ignore templates that are unavailable or that have been turned off
@@ -120,17 +119,23 @@ class SP_Template_Loader {
if ( ! isset( $template['option'] ) ) continue; if ( ! isset( $template['option'] ) ) continue;
if ( 'yes' !== get_option( $template['option'], sp_array_value( $template, 'default', 'yes' ) ) ) continue; if ( 'yes' !== get_option( $template['option'], sp_array_value( $template, 'default', 'yes' ) ) ) continue;
// Add to tabs // Put tab content into buffer
$tabs .= '<li class="sp-tab-menu-item' . ( 0 === $i ? ' sp-tab-menu-item-active' : '' ) . '"><a href="#sp-tab-content-' . $key . '" data-sp-tab="' . $key . '">' . apply_filters( 'gettext', $template['title'], $template['title'], 'sportspress' ) . '</a></li>'; ob_start();
// Render the template
echo '<div class="sp-tab-content sp-tab-content-' . $key . '" id="sp-tab-content-' . $key . '"' . ( 0 === $i ? ' style="display: block;"' : '' ) . '>';
if ( 'content' === $key ) { if ( 'content' === $key ) {
echo $content; echo $content;
} else { } else {
call_user_func( $template['action'] ); call_user_func( $template['action'] );
} }
echo '</div>'; $buffer = ob_get_clean();
// Continue if tab content is empty
if ( empty( $buffer ) ) continue;
// Add to tabs
$tabs .= '<li class="sp-tab-menu-item' . ( 0 === $i ? ' sp-tab-menu-item-active' : '' ) . '"><a href="#sp-tab-content-' . $key . '" data-sp-tab="' . $key . '">' . apply_filters( 'gettext', $template['title'], $template['title'], 'sportspress' ) . '</a></li>';
// Render the template
$tab_content .= '<div class="sp-tab-content sp-tab-content-' . $key . '" id="sp-tab-content-' . $key . '"' . ( 0 === $i ? ' style="display: block;"' : '' ) . '>' . $buffer . '</div>';
$i++; $i++;
} }
@@ -141,7 +146,7 @@ class SP_Template_Loader {
$ob .= '<ul class="sp-tab-menu">' . $tabs . '</ul>'; $ob .= '<ul class="sp-tab-menu">' . $tabs . '</ul>';
} }
$ob .= ob_get_clean(); $ob .= $tab_content;
$ob .= '</div>'; $ob .= '</div>';
} }