1. Home
  2. Docs
  3. Application Framework
  4. Annotations Reference
  5. Admin Page

Admin Page

@MWP\WordPress\AdminPage( title="Admin Page", menu="Admin Page", slug="adminpage" )

Using this annotation will create a new admin page in the WP Admin.

@Params

title="Page Title" (required) – The page title
slug="pageslug" (required) – The slug used in the url to access this page
menu="Menu Title" (optional) – The menu link title
capability="manage_options" (optional) / default: ‘manage_options’ – Capability required for access
icon="admin-page" (optional) / default: ‘none’ – The menu link icon to use
position=0 (optional) / default: null – The ordering position of the menu link
parent="parentslug" Only needed when menu type=submenu. This is the page slug of the parent menu item.
type="menu" (optional) / default: ‘menu’ – The type of menu ( menu, submenu, dashboard, posts, media, pages, comments, theme, plugins, users, tools, settings)
for="site" (optional) / default: ‘site’ – The location where the menu/page should appear ( site, network, all )

The admin page annotation can be used on either a class itself or a method within a class.

@Example Code

When it is used on the class itself, the class becomes a page controller for the admin page.

The default method that will be used to generate the page will be the do_index() method. If the url contains a &do=action parameter, the corresponding method do_action() on the class will be called to process and output the page. This allows you to have one admin controller that can have various different screens all contained within the same class.

Also, if your controller contains an init() method, that method will be called whenever your admin page is being accessed. You can use it to load scripts, styles, etc.

/**
 * An admin page controller
 *
 * @MWP\WordPress\AdminPage( title="Admin Page", menu="Admin Page", slug="adminpage" )
 */
class AdminPage 
{
    public function init()
    {
        // load scripts, styles, etc.
    }

    // stuff to do when page is first accessed
    public function do_index()
    {
        echo "Are you ready to get started?";
    }

    // stuff to do when do=hello in url
    public function do_hello()
    {
        echo "Hello Dollie.";
    }
}

As A Callback

When the annotation is used on a class method, then the page is routed to that method regardless of any parameters in the url.

class AdminPage
{
    /**
     * An admin page function
     *
     * @MWP\WordPress\AdminPage( title="Admin Page", menu="Admin Page", slug="adminpage" )
     */
    public function adminPageContent()
    {
        // stuff to do when page is first accessed
        if ( ! isset( $_REQUEST[ 'do' ] ) or ! $_REQUEST[ 'do' ] )
        {
            echo "Are you ready to get started?";
            return;
        }

        // stuff to do when do=hello 
        if ( $_REQUEST[ 'do' ] = 'hello' )
        {
            echo "Hello Dollie.";
            return;
        }
    }
}
Was this article helpful to you? Yes No

How can we help?