Skip to content

Instantly share code, notes, and snippets.

@wpmark
Created March 18, 2015 19:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save wpmark/1dba36c8a04160ea7709 to your computer and use it in GitHub Desktop.
Save wpmark/1dba36c8a04160ea7709 to your computer and use it in GitHub Desktop.
WordPress Dashboard Tabs
<?php
/***************************************************************
* Function wpbasis_dashboard_content()
* Pulls in the new dashboard page content from plugin file
***************************************************************/
function wpbasis_dashboard() {
/* check for a dashboard content file in the theme folder */
if( file_exists( STYLESHEETPATH . '/wpbasis/dashboard.php' ) ) {
/* load the dashboard content file from the theme folder */
get_template_part( 'wpbasis/dashboard', 'content' );
/* lets output the content of the dashboard */
} else {
?>
<div class="wrap about-wrap wpbasis-dashboard-wrap">
<h1><?php bloginfo( 'name' ); ?><br />Dashboard</h1>
<?php
/***************************************************************
* @hooked wpbasis_dashboard_about_text
***************************************************************/
do_action( 'wpbasis_dashboard_about_text' );
?>
<div class="wpbasis-tabs-wrapper">
<ul class="wpbasis-tabs">
<?php
/***************************************************************
* set an array of tab titles and ids
* the id set here should match the id given to the content wrapper
* which has the class wpbasis-tab-content included in the callback
* function
***************************************************************/
$wpbasis_dashboard_tabs = apply_filters(
'wpbasis_dashboard_tabs',
array(
'welcome' => array(
'id' => '#wpbasis-welcome',
'label' => 'Welcome',
),
)
);
/* check we have items to show */
if( ! empty( $wpbasis_dashboard_tabs ) ) {
/* loop through each item */
foreach( $wpbasis_dashboard_tabs as $wpbasis_dashboard_tab ) {
?>
<li><a href="<?php echo esc_attr( $wpbasis_dashboard_tab[ 'id' ] ); ?>"><?php echo esc_html( $wpbasis_dashboard_tab[ 'label' ] ); ?></a></li>
<?php
}
}
?>
</ul>
<?php
/* set an array of tab content blocks */
$wpbasis_dashboard_tabs_contents = apply_filters(
'wpbasis_dashboard_tabs_contents',
array(
'welcome' => array(
'callback' => 'wpbasis_dashboard_welcome_tab',
),
)
);
/* check we have items to show */
if( ! empty( $wpbasis_dashboard_tabs_contents ) ) {
/* loop through each item */
foreach( $wpbasis_dashboard_tabs_contents as $wpbasis_dashboard_tabs_content ) {
/* run the callback function for showing the content */
$wpbasis_dashboard_tabs_content[ 'callback' ]();
}
}
?>
</div><!-- // wpbasis-tabs-wrapper -->
</div>
<?php
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment