Get Started

Five Basic Steps

To create an option page with this framework, follow these steps.

1. Include the Library Class

if ( !class_exists( 'Admin_Page_Framework' ) ) 
    include_once( '/classes/admin-page-framework.php' );

2. Extend the Library Class

Admin_Page_Framework is the class name defined by this framework. The extended class name is up to your choice. As an example, here, APF_CreateSettingPage is used.

class APF_CreateSettingPage extends Admin_Page_Framework {
}

3. Define the SetUp() Method.

The SetUp() method is a special method defined by this framework that is automatically loaded when the admin menu is about to be created (with the the admin_menu hook). So we just overwrite the method in the extended class. All settings need to be set within this method.

function SetUp() {
    $this->SetRootMenu( 'Settings' );               // specifies to which parent menu to belong.
    $this->AddSubMenu(  'My First Setting Page',    // page and menu title
                        'my_first_settings_page' ); // page slug
}

4. Define methods for hooks.

The method name is made up of the hook prefix + the page slug. Here, do_ is used as an example. There are lots of available hooks supported by this framework.

function do_my_first_settings_page() {  // do_ + pageslug
    ?>
    <h3>Say Something</h3>
    <p>This is my first admin page!</p>
    <?php
}

For available action hooks and filters, please refer to Hooks and Callbacks.

5. Instantiate the Class

new APF_CreateSettingPage;

Simple Example Plugin

<?php
/* Plugin Name: Admin Page Framework - 0. Simple Example */

if ( !class_exists( 'Admin_Page_Framework' ) )
    include_once( '/classes/admin-page-framework.php' );

class APF_MyClass extends Admin_Page_Framework {

    function Setup() {    // The Setup() method must be defined
        $this->SetRootMenu( 'Settings' );    // specifies which top level menu to add the sub pages

        $this->AddSubMenu( 'My Page',        // page and menu title
                            'mypage' );    // page slug
    }
    function do_mypage() {    // do_ + pageslug
        ?>
        <h3>Hello!</h3>
        <p>This is my first admin page!</p>
        <?php
    }
}
new APF_MyClass;

Screenshot

screenshot_demo_00.jpg

2 thoughts on “Get Started

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>