Admin Page Framework Documentation
  • Package
  • Class
  • Tree

Packages

  • AdminPageFramework
    • Factory
    • FieldType
    • MetaBox
    • NetworkAdmin
      • Page
    • Page
    • PageMetaBox
    • PostType
    • TaxonomyField
    • Widget

Classes

  • AdminPageFramework_Factory_Controller
  • AdminPageFramework_Factory_Model

Class AdminPageFramework_Factory_Controller

Provides methods for models.

AdminPageFramework_Factory_Router
Extended by AdminPageFramework_Factory_Model
Extended by AdminPageFramework_Factory_View
Extended by AdminPageFramework_Factory_Controller

Indirect known subclasses

AdminPageFramework, AdminPageFramework_Menu, AdminPageFramework_PostType, AdminPageFramework_PostType_Controller, AdminPageFramework_PostType_Model, AdminPageFramework_PostType_Router, AdminPageFramework_PostType_View, AdminPageFramework_Setting, AdminPageFramework_TaxonomyField, AdminPageFramework_Widget, AdminPageFramework_Widget_Controller, AdminPageFramework_Widget_Model, AdminPageFramework_MetaBox, AdminPageFramework_Widget_Router, AdminPageFramework_Widget_View, AdminPageFramework_MetaBox_Page, AdminPageFramework_MetaBox_Page_Controller, AdminPageFramework_MetaBox_Page_Model, AdminPageFramework_MetaBox_Page_Router, AdminPageFramework_MetaBox_Page_View, AdminPageFramework_NetworkAdmin, AdminPageFramework_Page

Abstract
Package: AdminPageFramework\Factory
Since: 3.0.4
Located at factory/AdminPageFramework_Factory/AdminPageFramework_Factory_Controller.php

Methods summary

public
# setUp( )
public
# enqueueStyle( mixed $sSRC, mixed $_vArg2 = null )
public
# enqueueScripts( mixed $aSRCs, mixed $_vArg2 = null )
public
# enqueueScript( mixed $sSRC, mixed $_vArg2 = null )
public
# addHelpText( mixed $sHTMLContent, mixed $sHTMLSidebarContent = "" )

Adds the given HTML text to the contextual help pane.

Adds the given HTML text to the contextual help pane.

The help tab will be the meta box title and all the added text will be inserted into the content area within the tab.

Example

$this->addHelpText(
__( 'This text will appear in the contextual help pane.', 'admin-page-framework-demo' ),
__( 'This description goes to the sidebar of the help pane.', 'admin-page-framework-demo' )
);

Since

2.1.0

Remark

This method just adds the given text into the class property. The actual registration will be performed with the replyToRegisterHelpTabTextForMetaBox() method.
public
# addSettingSections( array|string $aSection1, array $aSection2 = null, array $_and_more = null )

Adds the given form section items into the property.

Adds the given form section items into the property.

The passed section array must consist of the following keys.

Example

$this->addSettingSections(
array(
     'section_id'    => 'text_fields',
     'page_slug'     => 'first_page',
     'tab_slug'      => 'textfields',
     'title'         => 'Text Fields',
     'description'   => 'These are text type fields.',
     'order'         => 10,
),
array(
     'section_id'    => 'selectors',
     'page_slug'     => 'first_page',
     'tab_slug'      => 'selectors',
     'title'         => 'Selectors and Checkboxes',
     'description'   => 'These are selector type options such as dropdown lists, radio buttons, and checkboxes',
)

Parameters

$aSection1
array|string
the section array or the target page slug. If the target page slug is set, the next section array can omit the page slug key. Section Array
  • section_id - (string) the section ID. Avoid using non-alphabetic characters except underscore and numbers.
  • title - (optional, string) the title of the section.
  • capability - (optional, string) the access level of the section. If the page visitor does not have sufficient capability, the section will be invisible to them.
  • if - (optional, boolean) if the passed value is false, the section will not be registered.
  • order - (optional, integer) the order number of the section. The higher the number is, the lower the position it gets.
  • help - (optional, string) the help description added to the contextual help tab.
  • help_aside - (optional, string) the additional help description for the side bar of the contextual help tab.
$aSection2
array
(optional) another section array.
$_and_more
array
(optional) add more section array to the next parameters as many as necessary.

Since

3.0.0

Remark

Accepts variadic parameters; the number of accepted parameters are not limited to three.
The target section tab slug will be reset once the method returns.
public
# addSettingSection( array|string $aSection )

A singular form of the adSettingSections() method which takes only a single parameter.

A singular form of the adSettingSections() method which takes only a single parameter.

This is useful when adding section arrays in loops.

Parameters

$aSection
array|string
the section array. If a string is passed, it is considered as a target page slug that will be used as a page slug element from the next call so that the element can be ommited.

Since

3.0.0 Changed the scope to public from protected.

Remark

The actual registration will be performed in the _replyToRegisterSettings() method with the admin_menu hook.
The $oForm property should be created in each extended class.
public
# addSettingFields( array $aField1, array $aField2 = null, array $_and_more = null )

Adds the given field array items into the field array property by the given field definition array(s).

Adds the given field array items into the field array property by the given field definition array(s).

The field definition array requires specific keys. Refer to the parameter section of this method.

Example

    $this->addSettingFields(
    array(
        'field_id'       => 'sample_metabox_text_field',
        'title'          => 'Text Input',
        'description'    => 'The description for the field.',
        'type'           => 'text',
    ),
    array(
        'field_id'       => 'sample_metabox_textarea_field',
        'title'          => 'Textarea',
        'description'    => 'The description for the field.',
        'type'           => 'textarea',
        'default'        => 'This is a default text value.',
    )
);

Parameters

$aField1
array
the field definition array.

Built-in Field Types

  • text - a normal field to enter text input.
  • text - a masked text input field.
  • textarea - a text input field with multiple lines. It supports rich text editor.
  • radio - a set of radio buttons that lets the user pick an option.
  • checkbox - a check box that lets the user enable/disable an item.
  • select - a drop-down list that lest the user pick one or more item(s) from a list.
  • hidden - a hidden field that will be useful to insert invisible values.
  • file - a file uploader that lets the user upload files.
  • image - a custom text field with the image uploader script that lets the user set the image URL.
  • media - a custom text field with the media uploader script that lets the user set the file URL.
  • color - a custom text field with the color picker script.
  • submit - a submit button that lets the user send the form.
  • export - a custom submit field that lets the user export the stored data.
  • import - a custom combination field of the file and the submit fields that let the user import data.
  • posttype - a check-list of post types enabled on the site.
  • taxonomy - a set of check-lists of taxonomies enabled on the site in a tabbed box.
  • size - a combination field of the text and the select fields that let the user set sizes with a selectable unit.
  • section_title - [3.0.0+] a text field type that will be placed in the section title so that it lets the user set the section title. Note that only one field with this field type is allowed per a section.

Field Definition Array

  • field_id - ( required, string ) the field ID. Avoid using non-alphabetic characters except underscore and numbers.
  • type - ( required, string ) the type of the field. The supported types are listed below.
  • section_id - ( optional, string ) the section ID that the field belongs to. If not set, the internal _default section ID will be assigned.
  • title - ( optional, string ) the title of the section.
  • description - ( optional, string ) the description of the field which is inserted into the after the input field tag.
  • tip - ( optional, string ) the tip for the field which is displayed when the mouse is hovered over the field title.
  • capability - ( optional, string ) the http://codex.wordpress.org/Roles_and_Capabilities">access level of the section. If the page visitor does not have sufficient capability, the section will be invisible to them.
  • error_message - ( optional, string ) the error message to display above the input field.
  • before_field - ( optional, string ) the HTML string to insert before the input field output.
  • after_field - ( optional, string ) the HTML string to insert after the input field output.
  • if - ( optional, boolean ) if the passed value is false, the section will not be registered.
  • order - ( optional, integer ) the order number of the section. The higher the number is, the lower the position it gets.
  • label - ( optional, string ) the text label(s) associated with and displayed along with the input field. Some input types can ignore this key.
  • default - ( optional, string|array ) the default value(s) assigned to the input tag's value attribute.
  • value - ( optional, string|array ) the value(s) assigned to the input tag's value attribute to override the default and the stored value.
  • delimiter - ( optional, string ) the HTML string that delimits multiple elements. This is available if the label key is passed as array. It will be enclosed in inline-block elements so the passed HTML string should not contain block elements.
  • before_input - ( optional, string ) the HTML string inserted right before the input tag. It will be enclosed in the label tag so the passed HTML string should not contain block elements.
  • after_input - ( optional, string ) the HTML string inserted right after the input tag. It will be enclosed in the label tag so the passed HTML string should not contain block elements.
  • label_min_width - ( optional, string ) the inline style property of the min-width of the label tag for the field. If the unit is not specified, 'px' is applied. Default: <span class="php-num">120</span>. e.g. <span class="php-num">100</span>%
  • help - ( optional, string ) the help description added to the contextual help tab.
  • help_aside - ( optional, string ) the additional help description for the side bar of the contextual help tab.
  • repeatable - [3.0.0+] ( optional, array|boolean ) whether the fields should be repeatable. If it yields true, the plus and the minus buttons appear next to each field that lets the user add/remove the fields. Optionally an setting array can be passed.
    Repeatable Fields Setting Array
    • max - the allowed maximum number of fields to be repeated.
    • min</string> - the allowed minimum number of fields to be repeated.
  • sortable - [3.0.0+] ( optional, boolean ) whether the fields should be sortable. If it yields true, the fields will be enclosed in a draggable box.
  • attributes - [3.0.0+] ( optional, array ) holds key-value pairs representing the attribute and its property. Note that some field types have specific keys in the first dimensions. e.g.array( 'class' => 'my_custom_class_selector', 'style' => 'background-color:#777', 'size' => 20, )
  • show_title_column - [3.0.0+] ( optional, boolean ) If true, the field title column will be omitted from the output.
  • hidden - [3.0.0+] ( optional, boolean ) If true, the entire field row output will be invisible with the inline style attribute of style="display:none".

Field Type Specific Keys

Each field type uses specific array keys.

  • text - a text input field which allows the user to type text.
  • password - a password input field which allows the user to type text.
  • number, range - HTML5 input field types. Some browsers do not support these.
  • textarea - a textarea input field. The following array keys are supported.
    • rich - 2.1.2+ to make it a rich text editor pass a non-empty value. It accept a setting array of the _WP_Editors class defined in the core. For more information, see the argument section of this page.
  • radio - a radio button input field.
  • checkbox - a check box input field.
  • select - a drop-down input field.
    • is_multiple - ( optional, boolean ) if this is set to true, the multiple attribute will be inserted into the field input tag, which enables the multiple selections for the user.
  • size - a size input field. This is a combination of number and select fields.
    • units - ( optional, array ) defines the units to show. e.g. array( 'px' => 'px', '%' => '%', 'em' => 'em' ) Default: array( 'px' => 'px', '%' => '%', 'em' => 'em', 'ex' => 'ex', 'in' => 'in', 'cm' => 'cm', 'mm' => 'mm', 'pt' => 'pt', 'pc' => 'pc' )
    • is_multiple - ( optional, boolean ) if this is set to true, the multiple attribute will be inserted into the field input tag, which enables the multiple selections for the user.
    • attributes - [3.0.0+] ( optional, array ) The attributes array of this field type has four initial keys: size, unit, optgroup, and option and they have a regular attribute array in each.
  • hidden - a hidden input field.
  • file - a file upload input field.
  • submit - a submit button input field.
    • href - ( optional, string ) the url(s) linked to the submit button.
    • redirect_url - ( optional, string ) the url(s) redirected to after submitting the input form.
    • reset - [2.1.2+] ( optional, boolean ) the option key to delete. Set 1 for the entire option.
  • import - an import input field. This is a custom file and submit field.
    • option_key - ( optional, string ) the option table key to save the importing data.
    • format - ( optional, string ) the import format. json, or array is supported. Default: array
    • is_merge - ( optional, boolean ) [2.0.5+] determines whether the imported data should be merged with the existing options.
  • export - an export input field. This is a custom submit field.
    • file_name - ( optional, string ) the file name to download.
    • format - ( optional, string ) the format type. array, json, or text is supported. Default: array.
    • data - ( optional, string|array|object ) the data to export.
  • image - an image input field. This is a custom text field with an attached JavaScript script.
    • show_preview - ( optional, boolean ) if this is set to false, the image preview will be disabled.
    • attributes_to_store - [2.1.3+] ( optional, array ) the array of the attribute names of the image to save. If this is set, the field will be an array with the specified attributes. The supported attributes are, 'title', 'alt', 'width', 'height', 'caption', 'id', 'align', and 'link'. Note that for external URLs, ID will not be captured. e.g. 'attributes_to_store' => array( 'id', 'caption', 'description' )
    • allow_external_source - [2.1.3+] ( optional, boolean ) whether external URL can be set via the uploader.
    • attributes - [3.0.0+] ( optional, array ) The attributes array of this field type has three keys: input, button, and preview and they have a regular attribute array in each.
  • media - [2.1.3+] a media input field. This is a custom text field with an attached JavaScript script.
    • attributes_to_store - [2.1.3+] ( optional, array ) the array of the attribute names of the image to save. If this is set, the field will be an array with the specified attributes. The supported attributes are, 'id', 'caption', and 'description'. Note that for external URLs, ID will not be captured. e.g. 'attributes_to_store' => array( 'id', 'caption', 'description' )
    • allow_external_source - [2.1.3+] ( optional, boolean ) whether external URL can be set via the uploader.
  • color - a color picker input field. This is a custom text field with a JavaScript script.
  • taxonomy - a taxonomy check list. This is a set of check boxes listing a specified taxonomy. This does not accept to create multiple fields by passing an array of labels.
    • taxonomy_slugs - ( optional, array ) the taxonomy slug to list.
    • max_width - ( optional, string ) the inline style property value of max-width of this element. Include the unit such as px, %. Default: 100%
    • height - ( optional, string ) the inline style property value of height of this element. Include the unit such as px, %. Default: 250px
  • posttype - a post-type check list. This is a set of check boxes listing post type slugs.
    • slugs_to_remove - ( optional, array ) the post type slugs not to be listed. e.g.array( 'revision', 'attachment', 'nav_menu_item' )
$aField2
array
(optional) another field array.
$_and_more
array
(optional) add more field arrays to the next parameters as many as necessary.

Since

2.0.0

Remark

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

Adds the given field array items into the field array property.

Adds the given field array items into the field array property.

Identical to the addSettingFields() method except that this method does not accept enumerated parameters.

Examples

$this->addSettingField(
    array(
        'field_id'    => 'metabox_text_field',
        'type'        => 'text',
        'title'       => __( 'Text Input', 'admin-page-framework-demo' ),
        'description' => __( 'The description for the field.', 'admin-page-framework-demo' ),
        'help'        => 'This is help text.',
        'help_aside'  => 'This is additional help text which goes to the side bar of the help pane.',
    )
);

Since

2.1.2
3.0.0 The scope changed to public to indicate the users will use.

Remark

The $oForm property should be created in each extended class.
public
# setFieldErrors( array $aErrors )

Sets the field error array.

Sets the field error array.

This is normally used in validation callback methods when the submitted user's input data have an issue. This method saves the given array in a temporary area( transient ) of the options database table.

Example

public function validation_APF_Demo_verify_text_field_submit( $aNewInput, $aOldOptions ) {

     // 1. Set a flag.
     $bVerified = true;

     // 2. Prepare an error array.
     $aErrors = array();

     // 3. Check if the submitted value meets your criteria.
     if ( ! is_numeric( $aNewInput['verify_text_field'] ) ) {
         $aErrors['verify_text_field'] = __( 'The value must be numeric:', 'admin-page-framework-demo' )
             . $aNewInput['verify_text_field'];
         $bVerified = false;
     }

     // 4. An invalid value is found.
     if ( ! $bVerified ) {

         // 4-1. Set the error array for the input fields.
         $this->setFieldErrors( $aErrors );
         $this->setSettingNotice( 'There was an error in your input.' );
         return $aOldOptions;

     }

     return $aNewInput;

}

Parameters

$aErrors
array
$aErrors the field error array. The structure should follow the one contained in the submitted $_POST array.

Since

3.0.4
public
# setSettingNotice( string $sMessage, string $sType = 'error', array $asAttributes = array(), boolean $bOverride = true )

Sets the given message to be displayed in the next page load.

Sets the given message to be displayed in the next page load.

This is used to inform users about the submitted input data, such as "Updated successfully." or "Problem occurred." etc. and normally used in validation callback methods.

Example

if ( ! $bVerified ) {
      $this->setFieldErrors( $aErrors );
      $this->setSettingNotice( 'There was an error in your input.' );
      return $aOldPageOptions;
}

Parameters

$sMessage
string
$sMessage the text message to be displayed.
$sType
string
$sType (optional) the type of the message, either "error" or "updated" is used.
$asAttributes
array
$asAttributes (optional) the tag attribute array applied to the message container HTML element. If a string is given, it is used as the ID attribute value.
$bOverride
boolean
$bOverride (optional) false: do not override when there is a message of the same id. true: override the previous one.

Since

3.0.4
public boolean
# hasSettingNotice( string $sType = '' )

Checks if an error settings notice has been set.

Checks if an error settings notice has been set.

This is used in the internal validation callback method to decide whether the system error or update notice should be added or not. If this method yields true, the framework discards the system message and displays the user set notification message.

Parameters

$sType
string
$sType If empty, the method will check if a message exists in all types. Otherwise, it checks the existence of a message of the specified type.

Returns

boolean
True if a setting notice is set; otherwise, false.

Since

3.1.0

Methods inherited from AdminPageFramework_Factory_View

__construct(), _replyToGetFieldOutput(), _replyToPrintSettingNotice()

Methods inherited from AdminPageFramework_Factory_Model

_setUp()

Methods inherited from AdminPageFramework_Factory_Router

__call(), __get(), _getFormInstance(), _getHeadTagInstance(), _getHelpPaneInstance(), _getLinkInstancce(), _getPageLoadInfoInstance(), _isInThePage(), _isInstantiatable(), _replyToLoadComponents()

Magic methods summary

Properties summary

Properties inherited from AdminPageFramework_Factory_Router

$oProp

Admin Page Framework Documentation API documentation generated by ApiGen 2.8.0