Skip to content

Instantly share code, notes, and snippets.

@michaeluno
Last active December 24, 2015 09:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaeluno/9272557 to your computer and use it in GitHub Desktop.
Save michaeluno/9272557 to your computer and use it in GitHub Desktop.
Creates in-page tabs with Admin Page Framework v3. This is an example plugin introduced in the tutorial, Create In-page Tabs (http://en.michaeluno.jp/admin-page-framework/tutorials-v3/04-create-inpage-tabs/).
<?php
/*
Plugin Name: Admin Page Framework Tutorial 04 - Create In-page Tabs
Plugin URI: http://en.michaeluno.jp/admin-page-framework
Description: Creates in-page tabs with Admin Page Framework v3
Author: Michael Uno
Author URI: http://michaeluno.jp
Version: 1.0.1
Requirements: PHP 5.2.4 or above, WordPress 3.4 or above. Admin Page Framework 3.0.0 or above
*/
// Include the library file. Set your file path here.
include( dirname( dirname( __FILE__ ) ) . '/admin-page-framework/library/apf/admin-page-framework.php' );
// Extend the class
class APF_Tabs extends AdminPageFramework {
// Define the setUp() method to set how many pages, page titles and icons etc.
public function setUp() {
// Create the root menu
$this->setRootMenuPage(
'4. Tabs', // specify the name of the page group
'http://lh4.googleusercontent.com/-z7ydw-aPWGc/UwpeB96m5eI/AAAAAAAABjs/Brz6edaUB58/s800/demo04_16x16.png' // menu icon
);
// Add the sub menu item
$this->addSubMenuItems(
array(
'title' => 'My Tabs', // page title
'page_slug' => 'my_tabs', // page slug
'screen_icon' => 'https://lh3.googleusercontent.com/-Z5OeZOGzN3c/UilDgCX9WjI/AAAAAAAABS4/mf7L8GGJRTc/s800/demo04_01_32x32.png' // page screen icon for WP 3.7.x or below
)
);
// Add in-page tabs
$this->addInPageTabs(
'my_tabs', // set the target page slug so that the 'page_slug' key can be omitted from the next continuing in-page tab arrays.
array(
'tab_slug' => 'my_tab_a', // avoid hyphen(dash), dots, and white spaces
'title' => __( 'Tab A', 'admin-page-framework-tutorial' ),
),
array(
'tab_slug' => 'my_tab_b',
'title' => __( 'Tab B', 'admin-page-framework-tutorial' ),
),
array(
'tab_slug' => 'my_tab_c',
'title' => __( 'Tab C', 'admin-page-framework-tutorial' ),
)
);
$this->setPageHeadingTabsVisibility( false ); // disables the page heading tabs by passing false.
$this->setInPageTabTag( 'h2' ); // sets the tag used for in-page tabs
}
/**
* One of the predefined callback method.
*
* @remark content_{page slug}
*/
public function content_my_tabs( $sContent ) {
return $sContent
. '<h3>Page Content Filter</h3>'
. '<p>This is inserted by the the page <em>content_</em> filter, set in the <b><i>\'content_ + page slug\'</i></b> method.</p>';
}
/**
* One of the predefined callback method.
*
* @remark content_{page slug}_{tab slug}
*/
public function content_my_tabs_my_tab_b( $sContent ) {
return $sContent
. '<h3>Tab Content Filter</h3>'
. '<p>This is the second tab! This is inserted by the <b><i>\'content_ + page slug + _ + tab slug\'</i></b> method.</p>';
}
/**
* One of the predefined callback method.
*
* @remark content_{page slug}_{tab slug}
*/
function content_my_tabs_my_tab_c( $sContent ) {
return $sContent
. '<h3>Tab Content Filter</h3>'
. '<p>This is the third tab!.</p>';
}
}
// Instantiate the class object.
new APF_Tabs;
// That's it!! See, it's very short and easy, huh?
@codemascot
Copy link

content_ + page slug\ And content_ + page slug + _ + tab slug\ shows error. Any suggestion?

@sp1ke77
Copy link

sp1ke77 commented Jun 9, 2015

i have same error too...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment