Skip to content

Instantly share code, notes, and snippets.

@barbietunnie
Forked from danielpataki/enqueue.php
Last active September 13, 2015 17:35
Show Gist options
  • Save barbietunnie/32e6c3df0acfcceb62e8 to your computer and use it in GitHub Desktop.
Save barbietunnie/32e6c3df0acfcceb62e8 to your computer and use it in GitHub Desktop.
Tabbed Interface
function welcome_screen_assets( $hook ) {
if( 'dashboard_page_welcome-screen-about' == $hook ) {
wp_enqueue_style( 'welcome_screen_css', plugin_dir_url( __FILE__ ) . '/style.css' );
}
}
add_action( 'admin_enqueue_scripts', 'welcome_screen_assets' );
function welcome_screen_content() {
?>
<div class="wrap">
<h2>An Example Welcome Screen</h2>
<h2 class="nav-tab-wrapper">
<a class="nav-tab nav-tab-active" href="<?php echo admin_url() ?>/index.php?page=welcome-screen-about">Quick Guide</a>
<a class="nav-tab" href="<?php echo admin_url() ?>/index.php?page=welcome-screen-credits">Credits</a>
</h2>
<p>This is the main welcome screen content</p>
</div>
<?php
}
function welcome_screen_credits_content() {
?>
<div class="wrap">
<h2>Welcome Screen Credits</h2>
<h2 class="nav-tab-wrapper">
<a class="nav-tab" href="<?php echo admin_url() ?>/index.php?page=welcome-screen-about">Quick Guide</a>
<a class="nav-tab nav-tab-active" href="<?php echo admin_url() ?>/index.php?page=welcome-screen-credits">Credits</a>
</h2>
<p>This plugin was made by my dog, Bodza</p>
</div>
<?php
}
function welcome_screen_credits_content() {
?>
<div class="wrap">
<h2>Welcome Screen Credits</h2>
</div>
<?php
}
add_dashboard_page(
'Welcome Screen Credits',
'Welcome Screen Credits',
'read',
'welcome-screen-credits',
'welcome_screen_credits_content'
);
add_action( 'admin_head', 'welcome_screen_remove_menus' );
function welcome_screen_remove_menus() {
remove_submenu_page( 'index.php', 'welcome-screen-about' );
remove_submenu_page( 'index.php', 'welcome-screen-credits' );
}
wp_enqueue_script( 'welcome_screen_js', plugin_dir_url( __FILE__ ) . '/script.js', array( 'jquery' ), '1.0.0', true );
(function($) {
$(document).on( 'click', '.nav-tab-wrapper a', function() {
$('section').hide();
$('section').eq($(this).index()).show();
return false;
})
})( jQuery );
h2.nav-tab-wrapper {
margin:22px 0 0 0;
}
#sections {
padding:22px;
background: #fff;
border:1px solid #ccc;
border-top:0px;
}
section {
display:none;
}
section:first-child {
display:block;
}
.no-js h2.nav-tab-wrapper {
display:none;
}
.no-js #sections {
border-top:1px solid #ccc;
margin-top:22px;
}
.no-js section {
border-top: 1px dashed #aaa;
margin-top:22px;
padding-top:22px;
}
.no-js section:first-child {
margin:0px;
padding:0px;
border:0px;
}
function welcome_screen_content() {
?>
<div class="wrap">
<h2>An Example Welcome Screen</h2>
<h2 class="nav-tab-wrapper">
<a class="nav-tab nav-tab-active" href="<?php echo admin_url() ?>/index.php?page=welcome-screen-about">Quick Guide</a>
<a class="nav-tab" href="<?php echo admin_url() ?>/index.php?page=welcome-screen-credits">Credits</a>
</h2>
<p>This is the main welcome screen content</p>
</div>
<?php
}
register_activation_hook( __FILE__, 'welcome_screen_activate' );
function welcome_screen_activate() {
set_transient( '_welcome_screen_activation_redirect', true, 30 );
}
add_action( 'admin_init', 'welcome_screen_do_activation_redirect' );
function welcome_screen_do_activation_redirect() {
// Bail if no activation redirect
if ( ! get_transient( '_welcome_screen_activation_redirect' ) ) {
return;
}
// Delete the redirect transient
delete_transient( '_welcome_screen_activation_redirect' );
// Bail if activating from network, or bulk
if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
return;
}
// Redirect to bbPress about page
wp_safe_redirect( add_query_arg( array( 'page' => 'welcome-screen-about' ), admin_url( 'index.php' ) ) );
}
add_action('admin_menu', 'welcome_screen_pages');
function welcome_screen_pages() {
add_dashboard_page(
'Welcome To Welcome Screen',
'Welcome To Welcome Screen',
'read',
'welcome-screen-about',
'welcome_screen_content'
);
}
function welcome_screen_content() {
?>
<div class="wrap">
<h2>An Example Welcome Screen</h2>
<p>
You can put any content you like here from columns to sliders - it's up to you
</p>
</div>
<?php
}
add_action( 'admin_head', 'welcome_screen_remove_menus' );
function welcome_screen_remove_menus() {
remove_submenu_page( 'index.php', 'welcome-screen-about' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment