Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional tabs integration #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions inc/cmb2-tabs.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,33 @@ public function get_tabs() {
?>

<ul>
<?php foreach ( $this->setting['tabs'] as $key => $tab ): ?>
<li><a href="#<?php echo $tab['id']; ?>"><?php echo $tab['title']; ?></a></li>
<?php endforeach; ?>
<?php
foreach ( $this->setting['tabs'] as $key => $tab ):
$show_callback = $tab["show_on_cb"];
$show_callback = function_exists($show_callback) ? call_user_func($show_callback) : true;
if($show_callback) {
?>
<li><a href="#<?php echo $tab['id']; ?>"><?php echo $tab['title']; ?></a></li>
<?php
}
endforeach; ?>
</ul>

<?php foreach ( $this->setting['tabs'] as $key => $tab ): ?>
<div id="<?php echo $tab['id']; ?>">
<?php
foreach ( $this->setting['tabs'] as $key => $tab ):
$show_callback = $tab["show_on_cb"];
$show_callback = function_exists($show_callback) ? call_user_func($show_callback) : true;
if($show_callback) {
?>
<div id="<?php echo $tab['id']; ?>">
<?php
// Render fields from tab
$this->render_fields( $this->setting['config'], $tab['fields'], $this->object_id );
?>
</div>
<?php endforeach;
</div>
<?php
}
endforeach;

return ob_get_clean();
}
Expand Down Expand Up @@ -132,4 +146,4 @@ public static function save( $override_value, $value, $post_id, $data ) {
}
}

}
}