Admin Page Framework Documentation

Packages

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

Classes

  • AdminPageFramework_Factory_Controller

Resources

  • Tutorials
  • Support
  • Reporting Issues

Class AdminPageFramework_Factory_Controller

Provides methods for models.

Abstract
Package: AdminPageFramework\Common\Factory
Since: 3.0.4
Located at factory/_common/_abstract/AdminPageFramework_Factory_Controller.php

Methods summary

public
# setUp( )
public
# load( )
public boolean
# isInThePage( )

Allows the user to check if the current page belongs to the admin pages of the factory component.

Returns

boolean

Since

3.7.9
public
# setMessage( mixed $sKey, mixed $sMessage )

Sets a system message.

This can be used to replace the framework system messages such as "Allowed maximum number of fields is ...".

Since

3.7.0
public array|string
# getMessage( mixed $sKey = '' )

Returns the registered system message item(s).

Returns

array|string

Since

3.7.0
public
# addHelpText( mixed $sHTMLContent, mixed $sHTMLSidebarContent = "" )

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.

Since

2.1.0

Example

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

Remark

This method just adds the given text into the class property. The actual registration will be performed with the replyToRegisterHelpTabTextForMetaBox() method.
public
# addSettingSections( )

Adds sections.

It inserts the given section definition arrays into the class property and later they are parsed when sections are registered. The section definition array have required keys. Refer to the parameter section of this method.

Example

$this->addSettingSections(
      array(
           'section_id'    => 'text_fields',
           'title'         => __( 'Text Fields', 'your-text-domain' ),
           'description'   => __( 'These are text type fields.', 'your-text-domain' ),
      ),
      array(
           'section_id'    => 'selectors',
           'title'         => __( 'Selectors', 'your-text-domain' ),
           'description'   => __( 'These are selector type options such as dropdown lists, radio buttons, and checkboxes', 'your-text-domain' ),
      )
);

Since

3.0.0
3.5.3 Removed the parameter declarations as they are caught with func_get_args().

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 $aSectionset )

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

This is useful when adding section arrays in loops.

Parameters

$aSectionset
array|string
$aSection 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 omitted.

Section Definition 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.
  • section_tab_slug - (optional, string) the unique section tab slug to display the section in a tabbed container with other sections that have the same section tab slug.
  • hidden - (optional, boolean) [3.3.1+] whether or not the section should be hidden. Default: <span class="php-keyword1">false</span>.
  • attributes - (optional, string) [3.3.1+] An attribute array that applies to the section container element. e.g. array( 'data-custom_data' => 'my_custom_data' ) The following sub-elements are supported.
    • tab - (optional, array) An sub-attribute array that applies to the section tab <li> tag element.
  • class - (optional, array) [3.3.1+] class selector(s) appended to the section container element. The following sub-elements are supported.
    • tab - (optional, array) An sub-class array that applies to the section tab <li> tag element.
  • collapsible - (optional, array) [3.4.0+] class selector(s) appended to the section container element. The following sub-elements are supported.
    • title - (optional, string) the section title will be assigned by default in the section formatting method.
    • is_collapsed - (optional, boolean) whether it is already collapsed or expanded.
    • toggle_all_button - (optional, boolean|string|array) the position of where to display the toggle-all button that toggles the folding state of all collapsible sections. Accepts the following values. 'top-right', 'top-left', 'bottom-right', 'bottom-left'. If true is passed, the default 'top-right' will be used. To not to display, do not set any or pass false or null.
    • collapse_others_on_expand - (optional, boolean) whether the other collapsible sections should be folded when the section is unfolded. If the below container argument is set to section, this argument value does not take effect.
    • container - (optional, string) the container element that collapsible styling gets applied to. Either 'sections' or 'section' is accepted. Use 'section' for repeatable sections.
    • type - [3.7.0+] (optional, string) either box or button. Default: box. The button type only is supported when the container argument is set to section.
    ` $this->addSettingSections( array( 'section_id' => 'collapsible_repeatable_section', 'title' => __( 'Collapsible Repeatable Section', 'admin-page-framework-demo' ), 'collapsible' => array( 'toggle_all_button' => array( 'top-left', 'bottom-left' ), 'container' => 'section', ), 'repeatable' => true, ) ); `
  • repeatable - (optional, boolean|array) [3.0.0+] Indicates whether or not the section is repeatable. To set a minimum/maximum number of sections, pass an array with the key, min, and max. e.g. array( 'min' => 3, 'max' => 10 )
    • max - (optional, integer) The maximum number of repeated fields.
    • min - (optional, integer) The minimum number of repeated fields.
    • disabled - (optional, boolean|array) [3.8.13+]
      • message - (optional, string) the message to show when the user clicks on the Add repeatable button.
      • caption - (optional, string) the title of the modal window that displays the message. Default: Warning
      • box_width - (optional, integer) the width of the modal window that displays the message. Default: 300
      • box_width - (optional, integer) the height of the modal window that displays the message. Default: 100.
  • sortable - (optional, boolean) [3.6.0+] whether the section is sortable or not. In order for this option to be effective, the repeatable argument must be enabled.
  • content - (optional, string) [3.6.1+] a custom section output.
  • tip - (optional, string) [3.7.0+] a tool tip which pops up when the user hovers their mouse over the ? mark icon beside the title..
  • show_debug_info - (optional, boolean) [3.8.8+] Whether to show debug information such as field definition tool-tips.

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( )

Adds form fields.

It inserts the given field definition arrays into the class property and later they are parsed when fields are registered. The field definition array requires specific keys. Refer to the parameter section of this method.

Since

2.0.0
3.5.3 Removed the parameter declarations as they are caught with the func_get_args().

Remark

Accepts variadic parameters; the number of accepted parameters are not limited to three.
public
# addSettingField( array|string $asFieldset )

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.',
    )
);

Parameters

$asFieldset
array|string
$asField A field definition array or a string of the target section id.

Built-in Field Types

  • [text](./class-AdminPageFramework_FieldType_text.html) - a normal field to enter short text input.
  • [password](./class-AdminPageFramework_FieldType_text.html) - a masked text input field.
  • [textarea](./class-AdminPageFramework_FieldType_textarea.html) - a text input field with multiple lines. It supports rich text editors.
  • [radio](./class-AdminPageFramework_FieldType_radio.html) - a set of radio buttons that lets the user pick an option.
  • [checkbox](./class-AdminPageFramework_FieldType_checkbox.html) - a check box that lets the user enable/disable an item.
  • [select](./class-AdminPageFramework_FieldType_select.html) - a drop-down list that lest the user pick one or more item(s) from a list.
  • [hidden](./class-AdminPageFramework_FieldType_hidden.html) - a field with invisible input values.
  • [file](./class-AdminPageFramework_FieldType_file.html) - a file uploader that lets the user upload files.
  • [image](./class-AdminPageFramework_FieldType_image.html) - a text field with an image uploader that lets the user set the image URL.
  • [media](./class-AdminPageFramework_FieldType_media.html) - a text field with a media uploader that lets the user set the file URL.
  • [color](./class-AdminPageFramework_FieldType_color.html) - a text field with a color picker.
  • [submit](./class-AdminPageFramework_FieldType_submit.html) - a submit button that lets the user send the form.
  • [export](./class-AdminPageFramework_FieldType_export.html) - a custom submit field that lets the user export stored data.
  • [import](./class-AdminPageFramework_FieldType_import.html) - a custom combination field of file and submit fields that let the user import data.
  • [posttype](./class-AdminPageFramework_FieldType_posttype.html) - a check-list of post types enabled on the site.
  • [taxonomy](./class-AdminPageFramework_FieldType_taxonomy.html) - a set of check-lists of taxonomies enabled on the site in a tabbed box.
  • [size](./class-AdminPageFramework_FieldType_size.html) - a combination field of the text and the select fields that let the user set sizes with a selectable unit.
  • [section_title](./class-AdminPageFramework_FieldType_section_title.html) - [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.
  • [system](./class-AdminPageFramework_FieldType_system.html) - [3.3.0+] a custom text area field that displays the system information including the PHP settings, the framework version, MySQL version etc.
  • [inline_mixed](./class-AdminPageFramework_FieldType_inline_mixed.html) - [3.8.0+] a field that include inner fields with different field types.

Field Definition Arguments

  • field_id - (required, string) the field ID. Avoid using non-alphabetic characters except underscore and numbers.
  • type - (optional, string) the type of the field. The supported types are listed below. When creating nested fields, this argument can be omitted.
  • 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 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: 120. e.g. 100%
  • 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 - the allowed minimum number of fields to be repeated.
    • disabled - (optional, boolean|array) [3.8.13+]
      • message - (optional, string) the message to show when the user clicks on the Add repeatable button.
      • caption - (optional, string) the title of the modal window that displays the message. Default: Warning
      • box_width - (optional, integer) the width of the modal window that displays the message. Default: 300
      • box_width - (optional, integer) the height of the modal window that displays the message. Default: 100.
  • 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, ) Every field holds the following nested attribute definition arrays.
    • fieldrow - the td tag element containing the field output.
    • fieldset - the fieldset tag element containing the field output.
    • fields - the div tag element containing the sub-fields and the main field.
    • field - the div tag element containing each field.
  • 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".
  • save - [3.6.0+] (optional, boolean) If false, the field value will not be saved. Default: true
  • content - (optional, string|array) [3.6.1+] a custom section output. [3.8.0+] Supports an array to be passed for nested and inline-mixed fields. If an array holding field definitions is set, those fields will be nested.

    Example

    
      $this->addSettingFields(
          'my_section_id', // the target section ID - pass dimensional keys of the section
          array(
              'field_id'      => 'Y',
              'title'         => __( 'Y', 'admin-page-framework-loader' ),
              'description'   => __( 'By passing an array of field definition to the content argument, you can nest fields.', 'admin-page-framework-loader' )
                  . ' ' . __( 'Also the type argument can be omitted.', 'admin-page-framework-loader' ),
              'content'       => array(
                  array(
                      'field_id'      => 'i',
                      'title'         => __( 'i', 'admin-page-framework-loader' ),
                      'type'          => 'textarea',
                  ),
                  array(
                      'field_id'      => 'ii',
                      'title'         => __( 'ii', 'admin-page-framework-loader' ),
                      'type'          => 'color',
                  ),
                  array(
                      'field_id'      => 'iii',
                      'title'         => __( 'iii', 'admin-page-framework-loader' ),
                      'repeatable'    => true,
                      'sortable'      => true,
                      'content'       => array(
                          array(
                              'field_id'      => 'a',
                              'title'         => __( 'a', 'admin-page-framework-loader' ),
                              'type'          => 'image',
                              'attributes'    => array(
                                  'preview' => array(
                                      'style' => 'max-width: 200px;',
                                  ),
                              ),
                          ),
                          array(
                              'field_id'      => 'b',
                              'title'         => __( 'b', 'admin-page-framework-loader' ),
                              'content'       => array(
                                  array(
                                      'field_id'      => 'first',
                                      'title'         => __( '1st', 'admin-page-framework-loader' ),
                                      'type'          => 'color',
                                      'repeatable'    => true,
                                      'sortable'      => true,
                                  ),
                                  array(
                                      'field_id'      => 'second',
                                      'title'         => __( '2nd', 'admin-page-framework-loader' ),
                                      'type'          => 'size',
                                  ),
                                  array(
                                      'field_id'      => 'third',
                                      'title'         => __( '3rd', 'admin-page-framework-loader' ),
                                      'type'          => 'select',
                                      'label'         => array(
                                          'x' => 'X',
                                          'y' => 'Y',
                                          'z' => 'Z',
                                      ),
                                  ),
                              ),
                              // 'description'   => '',
                          ),
                          array(
                              'field_id'      => 'c',
                              'title'         => __( 'c', 'admin-page-framework-loader' ),
                              'type'          => 'radio',
                              'label'         => array(
                                  'a' => __( 'Apple', 'admin-page-framework-loader' ),
                                  'b' => __( 'Banana', 'admin-page-framework-loader' ),
                                  'c' => __( 'Cherry', 'admin-page-framework-loader' ),
                              ),
                              'default'       => 'b',
                          ),
                      )
                  ),
              ),
          )
      );
    
  • placement - [3.8.0+] (optional, string) Specifies where the field is rendered. Either normal section_title or field_title is accepted. field_title can only be used by nested fields defined in the content argument. Default: normal
  • show_debug_info - (optional, boolean) [3.8.8+] Whether to show debug information such as field definition tool-tips. Default: true.

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.

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 boolean
# hasFieldError( )

Check whether a user has set a field error(s) or not.

Returns

boolean
Whether or not a field error exists.

Since

3.3.0
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.

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) If true, only one message will be shown in the next page load. 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.

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

Magic methods summary

Properties summary

Related

Indirect known subclasses

AdminPageFramework, AdminPageFramework_Controller, AdminPageFramework_PageMetaBox_Controller, AdminPageFramework_PostType, AdminPageFramework_PostType_Controller, AdminPageFramework_PostType_View, AdminPageFramework_TaxonomyField, AdminPageFramework_TaxonomyField_Controller, AdminPageFramework_TaxonomyField_Model, AdminPageFramework_TermMeta, AdminPageFramework_UserMeta, AdminPageFramework_UserMeta_Controller, AdminPageFramework_Controller_Form, AdminPageFramework_UserMeta_View, AdminPageFramework_View, AdminPageFramework_Widget, AdminPageFramework_Widget_Controller, AdminPageFramework_Widget_View, AdminPageFramework_Controller_Menu, AdminPageFramework_Controller_Page, AdminPageFramework_MetaBox, AdminPageFramework_MetaBox_Controller, AdminPageFramework_MetaBox_View, AdminPageFramework_NetworkAdmin, AdminPageFramework_PageMetaBox

If you find undocumented functionality, please report it here.

Admin Page Framework