Instantly share code, notes, and snippets.
Demonstrates how to add sub-menu pages from a separate plugin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Admin Page Framework Demo - Add a Main Menu | |
* Plugin URI: http://en.michaeluno.jp/admin-page-framework | |
* Description: Adds a main menu and a sub-menu page. | |
* Author: Michael Uno | |
* Author URI: http://michaeluno.jp | |
* Version: 1.0.0 | |
* | |
*/ | |
include( dirname( dirname( __FILE__ ) ) . '/admin-page-framework/library/apf/admin-page-framework.php' ); | |
if ( ! class_exists( 'AdminPageFramework' ) ) { | |
return; | |
} | |
class APFDemo_MainMenu extends AdminPageFramework { | |
public function setUp() { | |
$this->setRootMenuPage( 'Main Menu' ); | |
$this->addSubMenuItems( | |
array( | |
'title' => __( 'Main Page', 'admin-page-framework-test' ), | |
'page_slug' => 'test_main_page', | |
) | |
); | |
$this->setPageHeadingTabsVisibility( false ); | |
} | |
public function do_test_main_page() { | |
echo "<h3>Main Page</h3>" | |
. "<p>This is a main page.</p>"; | |
} | |
} | |
new APFDemo_MainMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Admin Page Framework Demo - Add Sub-menu Pages | |
* Plugin URI: http://en.michaeluno.jp/admin-page-framework | |
* Description: Adds a sub-menu page | |
* Author: Michael Uno | |
* Author URI: http://michaeluno.jp | |
* Version: 1.0.0 | |
* | |
*/ | |
include( dirname( dirname( __FILE__ ) ) . '/admin-page-framework/library/apf/admin-page-framework.php' ); | |
if ( ! class_exists( 'AdminPageFramework' ) ) { | |
return; | |
} | |
class APFDemo_AddSubMenuPage extends AdminPageFramework { | |
public function setUp() { | |
$this->setRootMenuPageBySlug( 'APFDemo_MainMenu' ); | |
$this->addSubMenuItems( | |
array( | |
'title' => __( 'Sub-menu Page', 'admin-page-framework-demo' ), | |
'page_slug' => 'test_add_submenu_page', | |
) | |
); | |
} | |
public function do_test_add_submenu_page() { | |
echo "<h3>Sub-menu Page</h3>" | |
. "<p>This is a sub-menu page.</p>"; | |
} | |
} | |
new APFDemo_AddSubMenuPage; | |
class APFDemo_AddPageBySetUpFilter { | |
public function __construct() { | |
// set_up_{class name} | |
add_action( 'set_up_APFDemo_MainMenu', array( $this, 'setUp' ) ); | |
// do_{page slug} | |
add_action( 'do_test_page_x', array( $this, 'doPage' ) ); | |
} | |
public function setUp( $oFactory ) { | |
$oFactory->addSubMenuItems( | |
array( | |
'title' => __( 'Page X', 'admin-page-framework-demo' ), | |
'page_slug' => 'test_page_x', | |
) | |
); | |
} | |
public function doPage( $oFactory ) { | |
echo "<h3>Page X</h3>" | |
. "<p>Show some page contents here.</p>"; | |
} | |
} | |
new APFDemo_AddPageBySetUpFilter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment