Last active
December 24, 2015 08:28
-
-
Save michaeluno/9272529 to your computer and use it in GitHub Desktop.
Creates a page group with Admin Page Framework v3. This is an example plugin introduced in the tutorial, Create a Page Group (http://en.michaeluno.jp/admin-page-framework/tutorials-v3/03-create-a-page-group/).
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 Tutorial 03 - Create a Page Group | |
Plugin URI: http://en.michaeluno.jp/admin-page-framework | |
Description: Creates a page group 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. or above. Admin Page Framework 3.0.0 or above | |
*/ | |
include( dirname( __FILE__ ) . '/library/apf/admin-page-framework.php' ); | |
// Extend the class | |
class APF_CreatePageGroup 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( | |
'3. My Page Group', // specify the name of the page group | |
'https://lh5.googleusercontent.com/-vr0hu0pHcYo/UilDa_OwGYI/AAAAAAAABRg/29eid1MIBW0/s16/demo03_01_32x32.png' // use 16 by 16 image for the menu icon. | |
); | |
// Add the sub menus and the pages. | |
// The third parameter accepts screen icon url that appears at the top of the page. | |
$this->addSubMenuItems( | |
array( | |
'title' => 'First Page', // page title | |
'page_slug' => 'my_first_page', // page slug | |
'screen_icon' => 'https://lh5.googleusercontent.com/-vr0hu0pHcYo/UilDa_OwGYI/AAAAAAAABRg/29eid1MIBW0/s800/demo03_01_32x32.png' // page screen icon for WP 3.7.x or below | |
), | |
array( | |
'title' => 'Second Page', // page title | |
'page_slug' => 'my_second_page', // page slug | |
'screen_icon' => 'https://lh5.googleusercontent.com/-vr0hu0pHcYo/UilDa_OwGYI/AAAAAAAABRg/29eid1MIBW0/s800/demo03_01_32x32.png' // page screen icon for WP 3.7.x or below | |
), | |
array( | |
'title' => 'Third Page', // page title | |
'page_slug' => 'my_third_page', // page slug | |
'screen_icon' => 'https://lh5.googleusercontent.com/-vr0hu0pHcYo/UilDa_OwGYI/AAAAAAAABRg/29eid1MIBW0/s800/demo03_01_32x32.png' // page screen icon for WP 3.7.x or below | |
), | |
array( | |
'title' => __( 'Documentation', 'admin-page-framework-demo' ), | |
'href' => 'http://admin-page-framework.michaeluno.jp/en/v3/', | |
'show_page_heading_tab' => false, | |
) | |
); | |
// You can add more pages as many as you want! | |
} | |
// Action hook methods: 'do_' + page slug. | |
public function do_my_first_page() { | |
?> | |
<h3>Action Hook Method</h3> | |
<p>This is the first page from the action hook!</p> | |
<?php | |
} | |
public function do_my_second_page() { | |
?> | |
<h3>Action Hook Method</h3> | |
<p>This is the second page from the action hook!</p> | |
<?php | |
} | |
public function do_my_third_page() { | |
?> | |
<h3>Action Hook Method</h3> | |
<p>This is the third page from the action hook!</p> | |
<?php | |
} | |
/** | |
* Let's try using methods for filters. For filters, the method must return the output. | |
* The method name is content_ + page slug, similar to the above methods for action hooks. | |
*/ | |
public function content_my_first_page( $sContent ) { | |
return $sContent . '<h3>Filter Hook Method</h3><p>This is the first page from the filter! ( content_ + pageslug )</p>'; | |
} | |
public function content_my_second_page( $sContent ) { | |
return $sContent . '<h3>Filter Hook Method</h3><p>This is the second page from the filter! ( content_ + pageslug )</p>'; | |
} | |
public function content_my_third_page( $sContent ) { | |
return $sContent . '<h3>Filter Hook Method</h3><p>This is the third page from the filter! ( content_ + pageslug )</p>'; | |
} | |
// There are more available filters and actions! Please refer to Demo 06 - Hooks. | |
} | |
// Instantiate the class object. | |
new APF_CreatePageGroup; | |
// That's it!! See, it's very short and easy, huh? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment