Admin Page Framework Documentation

Packages

  • AdminPageFramework
    • Common
      • Factory
      • Form
        • FieldType
      • Utility
    • Factory
      • AdminPage
      • MetaBox
      • NetworkAdmin
      • PageMetaBox
      • PostType
      • TaxonomyField
      • TermMeta
      • UserMeta
      • Widget
    • Utility

Classes

  • AdminPageFramework
  • AdminPageFramework_Controller
  • AdminPageFramework_Controller_Form
  • AdminPageFramework_Controller_Menu
  • AdminPageFramework_Controller_Page
  • AdminPageFramework_View

Resources

  • Tutorials
  • Support
  • Reporting Issues

Class AdminPageFramework_Controller

Provides methods for the user to define how the outputs are displayed.

Abstract
Package: AdminPageFramework\Factory\AdminPage
Since: 3.3.1
Located at factory/admin_page/AdminPageFramework_Controller.php

Methods summary

public
# load( )

Called when one of the added admin page starts loading.

Alternatively the user may use the load_{instantiated class name} action hook and its auto-callback method.

Since

3.7.12

Overrides

AdminPageFramework_Factory_Controller::load
public
# setUp( )

The method for all the necessary set-ups.

The users should override this method to set-up necessary settings. To perform certain tasks prior to this method, use the start_{instantiated class name} hook that is triggered at the end of the class constructor.

Example

public function setUp() {
    $this->setRootMenuPage( 'APF Form' );
    $this->addSubMenuItems(
        array(
            'title' => 'Form Fields',
            'page_slug' => 'apf_form_fields',
        )
    );
}

Since

2.0.0
3.3.1 Moved from AdminPageFramework.

Remark

This is a callback for the wp_loaded hook.
In v1, this is triggered with the admin_menu hook; however, in v2, this is triggered with the wp_loaded hook.

Overrides

AdminPageFramework_Factory_Controller::setUp
public
# addHelpTab( array $aHelpTab )

Adds the given contextual help tab contents into the property.

Example

 $this->addHelpTab(
array(
     'page_slug                  => 'first_page', // (required)
     // 'page_tab_slug'          => null, // (optional)
     'help_tab_title'            => 'Admin Page Framework',
     'help_tab_id'               => 'admin_page_framework', // (required)
     'help_tab_content'          => __( 'This contextual help text can be set with the `addHelpTab()` method.', 'admin-page-framework' ),
     'help_tab_sidebar_content'  => __( 'This is placed in the sidebar of the help pane.', 'admin-page-framework' ),
)
);

Parameters

$aHelpTab
array
The help tab array.

Contextual Help Tab Array Structure

  • page_slug - (required) the page slug of the page that the contextual help tab and its contents are displayed.
  • page_tab_slug - (optional) the tab slug of the page that the contextual help tab and its contents are displayed.
  • help_tab_title - (required) the title of the contextual help tab.
  • help_tab_id - (required) the id of the contextual help tab.
  • help_tab_content - (optional) the HTML string content of the the contextual help tab.
  • help_tab_sidebar_content - (optional) the HTML string content of the sidebar of the contextual help tab.

Since

2.1.0
3.3.1 Moved from AdminPageFramework.

Remark

Called when registering setting sections and fields.
public array
# enqueueStyles( )

Enqueues styles by page slug and tab slug.

Use this method to pass multiple files to the same page.

Example

$this->enqueueStyle(
        array(
            dirname( APFDEMO_FILE ) . '/asset/css/code.css',
            dirname( APFDEMO_FILE ) . '/asset/css/code2.css',
        ),
        'apf_manage_options'     // page slug
);

Returns

array
The array holing the queued items.

Since

3.0.0
3.3.1 Moved from AdminPageFramework.
public string
# enqueueStyle( )

Enqueues a style by page slug and tab slug.

Example

$this->enqueueStyle(
     dirname( APFDEMO_FILE ) . '/asset/css/code.css',
     'apf_manage_options'    // page slug
);
$this->enqueueStyle(
     plugins_url( 'asset/css/readme.css' , APFDEMO_FILE ),
     'apf_read_me'           // page slug
);

Returns

string
The style handle ID. If the passed url is not a valid url string, an empty string will be returned.

Since

2.1.2
3.3.1 Moved from AdminPageFramework.

See

http://codex.wordpress.org/Function_Reference/wp_enqueue_style
public array
# enqueueScripts( )

Enqueues scripts by page slug and tab slug.

Example

$this->enqueueScripts(
    array(
         plugins_url( 'asset/js/test.js' , __FILE__ ), // source url or path
         plugins_url( 'asset/js/test2.js' , __FILE__ ),
    )
    'apf_read_me',     // page slug
);

Returns

array
The array holding the queued items.

Since

2.1.5
3.3.1 Moved from AdminPageFramework.
public string
# enqueueScript( )

Enqueues a script by page slug and tab slug.

Example

$this->enqueueScript(
     plugins_url( 'asset/js/test.js' , __FILE__ ), // source url or path
     'apf_read_me',     // page slug
     '',     // tab slug
     array(
         'handle_id'     => 'my_script', // this handle ID also is used as the object name for the translation array below.
         'translation'   => array(
             'a'                 => 'hello world!',
             'style_handle_id'   => $sStyleHandle, // check the enqueued style handle ID here.
         ),
     )
);

Returns

string
The script handle ID. If the passed url is not a valid url string, an empty string will be returned.

Since

2.1.2
3.0.0 Changed the scope to public
3.3.1 Moved from AdminPageFramework.

See

http://codex.wordpress.org/Function_Reference/wp_enqueue_script
public
# addLinkToPluginDescription( string $sTaggedLinkHTML1, string $sTaggedLinkHTML2 = null, string $_and_more = null )

Adds the given link(s) into the description cell of the plugin listing table.

Example

$this->addLinkToPluginDescription(
      "<a href='http://www.google.com'>Google</a>",
      "<a href='http://www.yahoo.com'>Yahoo!</a>"
);

Parameters

$sTaggedLinkHTML1
string
the tagged HTML link text.
$sTaggedLinkHTML2
string
(optional) another tagged HTML link text.
$_and_more
string
(optional) add more as many as want by adding items to the next parameters.

Since

2.0.0
3.0.0 Changed the scope to public from protected.
3.3.1 Moved from AdminPageFramework.

Remark

Accepts variadic parameters; the number of accepted parameters are not limited to three.
public
# addLinkToPluginTitle( string $sTaggedLinkHTML1, string $sTaggedLinkHTML2 = null, string $_and_more = null )

Adds the given link(s) into the title cell of the plugin listing table.

Example

$this->addLinkToPluginTitle(
      "<a href='http://www.wordpress.org'>WordPress</a>"
);

Parameters

$sTaggedLinkHTML1
string
the tagged HTML link text.
$sTaggedLinkHTML2
string
(optional) another tagged HTML link text.
$_and_more
string
(optional) add more as many as want by adding items to the next parameters.

Since

2.0.0
3.0.0 Changed the scope to public from protected.
3.3.1 Moved from AdminPageFramework.

Remark

Accepts variadic parameters; the number of accepted parameters are not limited to three.
public
# setPluginSettingsLinkLabel( mixed $sLabel )

Sets the label applied to the settings link which automatically embedded to the plugin listing table of the plugin title cell.

To disable the embedded settings link, pass an empty value.

Since

3.1.0
3.3.1 Moved from AdminPageFramework.
public
# setCapability( string $sCapability )

Sets the overall capability.

Example

$this->setCapability( 'read' ); // let subscribers access the pages.

Parameters

$sCapability
string
The access level for the created pages.

Since

2.0.0
3.0.0 Changed the scope to public from protected.
3.3.1 Moved from AdminPageFramework.

See

http://codex.wordpress.org/Roles_and_Capabilities
public
# setAdminNotice( string $sMessage, string $sClassSelector = 'error', string $sID = '' )

Sets an admin notice.

Example

$this->setAdminNotice( sprintf( 'Please click <a href="%1$s">here</a> to upgrade the options.', admin_url( 'admin.php?page="my_page"' ) ), 'updated' );

Parameters

$sMessage
string
The message to display
$sClassSelector
string
(optional) The class selector used in the message HTML element. 'error' and 'updated' are prepared by WordPress but it's not limited to them and can pass a custom name. Default: 'error'.
$sID
string
(optional) The ID of the message. If not set, the hash of the message will be used.

Since

2.1.2
3.0.0 Changed the scope to public from protected.
3.3.1 Moved from AdminPageFramework.

Remark

It should be used before the 'admin_notices' hook is triggered.
public
# setDisallowedQueryKeys( array|string $asQueryKeys, boolean $bAppend = true )

Sets the disallowed query keys in the links that the framework generates.

Example

$this->setDisallowedQueryKeys( 'my-custom-admin-notice' );

Parameters

$asQueryKeys
array|string
The query key(s) to disallow.
$bAppend
boolean
If true, the passed key(s) will be appended to the property; otherwise, it will override the property.

Since

2.1.2
3.0.0 It also accepts a string. Changed the scope to public.
3.3.1 Moved from AdminPageFramework.
public static mixed
# getOption( string $sOptionKey, string $asKey = null, mixed $vDefault = null )

Retrieves the saved option value from the given option key and the dimensional array key representation.

Example

$aData       = AdminPageFramework::getOption( 'APF' );
$aSection    = AdminPageFramework::getOption( 'APF', 'my_section' );
$sText       = AdminPageFramework::getOption( 'APF', array( 'my_section', 'my_text_field' ), 'foo' );
$sColor      = AdminPageFramework::getOption( 'APF', 'my_color_field', '#FFF' );

Parameters

$sOptionKey
string
$sOptionKey the option key of the options table.
$asKey
string
$asKey the representation of dimensional array keys. If the returning option structure is like the following, array( 'a' => array( 'b' => array( 'c' => 'ccc', ), ), ) then the value 'ccc' can be retrieved with the key representation array of array( 'a', 'b', 'c' )
$vDefault
mixed
$vDefault the default value that will be returned if nothing is stored.

Returns

mixed
If the field ID is not specified

Since

3.0.1
3.3.1 Moved from AdminPageFramework.

Magic methods summary

Properties summary

Related

Direct known subclasses

AdminPageFramework

Indirect known subclasses

AdminPageFramework_NetworkAdmin

If you find undocumented functionality, please report it here.

Admin Page Framework