Last active
December 25, 2015 03:34
-
-
Save michaeluno/951c739a0563f4d0789c to your computer and use it in GitHub Desktop.
Demonstrates a way to add a page-meta-box to an existing admin page created by Admin Page Framework. This is a sample plugin introduced in the tutorial Add a Meta Box in an Admin Page (http://en.michaeluno.jp/admin-page-framework/tutorials-v3/09-add-a-meta-box-in-an-admin-page/).
This file contains hidden or 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 09 - Add a Page Meta box | |
| * Plugin URI: http://en.michaeluno.jp/admin-page-framework | |
| * Description: Creates a page meta box and its form fields. | |
| * 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 376.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' ); | |
| class APF_Tutorial_SidePageMetaBox extends AdminPageFramework_PageMetaBox { | |
| /* | |
| * Use the setUp() method to define settings of this meta box. | |
| */ | |
| public function setUp() { | |
| /** | |
| * Adds setting fields in the meta box. | |
| */ | |
| $this->addSettingFields( | |
| array( | |
| 'field_id' => 'tutorial_page_metabox_color', | |
| 'type' => 'color', | |
| 'title' => __( 'Color', 'admin-page-framework-tutorial' ), | |
| ), | |
| array( | |
| 'field_id' => 'tutorial_metabox_text_field', | |
| 'type' => 'text', | |
| 'title' => __( 'Text Input', 'admin-page-framework-tutorial' ), | |
| ), | |
| array( | |
| 'field_id' => 'submit_in_page_meta_box', | |
| 'type' => 'submit', | |
| 'show_title_column' => false, | |
| 'label_min_width' => '', | |
| 'attributes' => array( | |
| 'field' => array( | |
| 'style' => 'float:right; width:auto;', | |
| ), | |
| ), | |
| ) | |
| ); | |
| // content_{page slug}_{tab slug} | |
| add_filter( 'content_my_tabs_my_tab_c', array( $this, 'replyToInsertContents' ) ); | |
| } | |
| /** | |
| * @callback filter content_{page slug}_{tab slug} | |
| * @return string | |
| */ | |
| public function replyToInsertContents( $sContent ) { | |
| $_aOptions = get_option( 'APF_Tabs', array() ); | |
| return $sContent | |
| . "<h3>" . __( 'Saved Options', 'admin-page-framework-tutorial' ) . "</h3>" | |
| . AdminPageFramework_Debug::getArray( $_aOptions ); | |
| } | |
| /** | |
| * The content filter callback method. | |
| * | |
| * Alternatively use the `content_{instantiated class name}` method instead. | |
| * @return string | |
| */ | |
| public function content( $sContent ) { | |
| $_sInsert = "<p>" . sprintf( __( 'This text is inserted with the <code>%1$s</code> method.', 'admin-page-framework-tutorial' ), __FUNCTION__ ) . "</p>"; | |
| return $sContent; | |
| } | |
| } | |
| new APF_Tutorial_SidePageMetaBox( | |
| null, // meta box id - passing null will make it auto generate | |
| __( 'Side Page Meta Box', 'admin-page-framework-tutorial' ), // title | |
| 'my_tabs', | |
| 'side', // context | |
| 'default' // priority | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment