Properties

$oScreen

$oScreen : object

Stores the screen object.

Type

object

Methods

registerSettings()

registerSettings() : void

Registers the setting sections and fields.

This methods passes the stored section and field array contents to the add_settings_section() and add_settings_fields() functions. Then perform register_setting().

The filters will be applied to the section and field arrays; that means that third-party scripts can modify the arrays. Also they get sorted before being registered based on the set order.

fixPageTitleForHiddenPages()

fixPageTitleForHiddenPages( $strAdminTitle,  $strPageTitle)

A callback function for the admin_title filter to fix the page title for hidden pages.

Parameters

$strAdminTitle
$strPageTitle

buildMenus()

buildMenus()

Builds menus.

finalizeInPageTabs()

finalizeInPageTabs() : void

Finalizes the in-page tab property array.

This finalizes the added in-page tabs and sets the default in-page tab for each page. Also this sorts the in-page tab property array. This must be done before registering settings sections because the default tab needs to be determined in the process.

setSettingNotice()

setSettingNotice(string $strMsg, string $strType, string $strID, integer $fOverride) : void

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 ( ! $fVerified ) { $this->setFieldErrors( $arrErrors ); $this->setSettingNotice( 'There was an error in your input.' ); return $arrOldPageOptions; }

Parameters

string $strMsg

the text message to be displayed.

string $strType

( optional ) the type of the message, either "error" or "updated" is used.

string $strID

( optional ) the ID of the message. This is used in the ID attribute of the message HTML element.

integer $fOverride

( optional ) false: do not override when there is a message of the same id. true: override the previous one.

addSettingSections()

addSettingSections(array $arrSection1, array $arrSection2, array $_and_more) : void

Adds the given form section items into the property.

The passed section array must consist of the following keys.

Section Array

  • strSectionID - ( string ) the section ID. Avoid using non-alphabetic characters exept underscore and numbers.
  • strPageSlug - ( string ) the page slug that the section belongs to.
  • strTabSlug - ( optional, string ) the tab slug that the section belongs to.
  • strTitle - ( optional, string ) the title of the section.
  • strCapability - ( optional, string ) the access level of the section. If the page visitor does not have sufficient capability, the section will be invisible to them.
  • fIf - ( optional, boolean ) if the passed value is false, the section will not be registered.
  • numOrder - ( optional, integer ) the order number of the section. The higher the number is, the lower the position it gets.
  • strHelp - ( optional, string ) the help description added to the contextual help tab.
  • strHelpAside - ( optional, string ) the additional help description for the side bar of the contextual help tab.

Example

$this->addSettingSections( array( 'strSectionID' => 'text_fields', 'strPageSlug' => 'first_page', 'strTabSlug' => 'textfields', 'strTitle' => 'Text Fields', 'strDescription' => 'These are text type fields.', 'numOrder' => 10, ), array( 'strSectionID' => 'selectors', 'strPageSlug' => 'first_page', 'strTabSlug' => 'selectors', 'strTitle' => 'Selectors and Checkboxes', 'strDescription' => 'These are selector type options such as dropdown lists, radio buttons, and checkboxes', )

Parameters

array $arrSection1

the section array.

array $arrSection2

( optional ) another section array.

array $_and_more

( optional ) add more section array to the next parameters as many as necessary.

addSettingSection()

addSettingSection(array $arrSection)

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

This is useful when adding section arrays in loops.

Parameters

array $arrSection

the section array.

removeSettingSections()

removeSettingSections(string $strSectionID1, string $strSectionID2, string $_and_more) : void

Removes the given section(s) by section ID.

This accesses the property storing the added section arrays and removes the specified ones.

Example

$this->removeSettingSections( 'text_fields', 'selectors', 'another_section', 'yet_another_section' );

Parameters

string $strSectionID1

the section ID to remove.

string $strSectionID2

( optional ) another section ID to remove.

string $_and_more

( optional ) add more section IDs to the next parameters as many as necessary.

addSettingFields()

addSettingFields(array $arrField1, array $arrField2, array $_and_more) : void

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

The passed field array must consist of the following keys.

Field Array

  • strFieldID - ( string ) the field ID. Avoid using non-alphabetic characters exept underscore and numbers.
  • strSectionID - ( string ) the section ID that the field belongs to.
  • strType - ( string ) the type of the field. The supported types are listed below.
  • strTitle - ( optional, string ) the title of the section.
  • strDescription - ( optional, string ) the description of the field which is inserted into the after the input field tag.
  • strTip - ( optional, string ) the tip for the field which is displayed when the mouse is hovered over the field title.
  • strCapability - ( 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.
  • strName - ( optional, string ) the name attribute value of the input tag instead of automatically generated one.
  • strError - ( optional, string ) the error message to display above the input field.
  • strBeforeField - ( optional, string ) the HTML string to insert before the input field output.
  • strAfterField - ( optional, string ) the HTML string to insert after the input field output.
  • fIf - ( optional, boolean ) if the passed value is false, the section will not be registered.
  • numOrder - ( optional, integer ) the order number of the section. The higher the number is, the lower the position it gets.
  • vLabel - ( optional|mandatory, string|array ) the text label(s) associated with and displayed along with the input field. Some input types can ignore this key while some require it.
  • vDefault - ( optional, string|array ) the default value(s) assigned to the input tag's value attribute.
  • vValue - ( optional, string|array ) the value(s) assigned to the input tag's value attribute to override the default or stored value.
  • vDelimiter - ( optional, string|array ) the HTML string that delimits multiple elements. This is available if the vLabel key is passed as array. It will be enclosed in inline-block elements so the passed HTML string should not contain block elements.
  • vBeforeInputTag - ( optional, string|array ) 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.
  • vAfterInputTag - ( optional, string|array ) 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.
  • vClassAttribute - ( optional, string|array ) the value(s) assigned to the input tag's class.
  • vLabelMinWidth - ( optional, string|array ) the inline style property of the min-width of the label tag for the field in pixel without the unit. Default: 120.
  • vDisable - ( optional, boolean|array ) if this is set to true, the disabled attribute will be inserted into the field input tag.
  • strHelp - ( optional, string ) the help description added to the contextual help tab.
  • strHelpAside - ( optional, string ) the additional help description for the side bar of the contextual help tab.

Field Types

Each field type uses specific array keys.

  • text - a text input field which allows the user to type text.
    • vReadOnly - ( optional, boolean|array ) if this is set to true, the readonly attribute will be inserted into the field input tag.
    • vSize - ( optional, integer|array ) the number that indicates the size of the input field.
    • vMaxLength - ( optional, integer|array ) the number that indicates the maxlength attribute of the input field.
    • fRepeatable - [2.1.3+] ( optional, boolean|array ) whether the fields should be repeatable. If is true, the plus and the minus buttons appear next to each field that lets the user add/remove the fields.
  • password - a password input field which allows the user to type text.
    • vReadOnly - ( optional, boolean|array ) if this is set to true, the readonly attribute will be inserted into the field input tag.
    • vSize - ( optional, integer|array ) the number that indicates the size of the input field.
    • vMaxLength - ( optional, integer|array ) the number that indicates the maxlength attribute of the input field.
    • fRepeatable - [2.1.3+] ( optional, boolean|array ) whether the fields should be repeatable. If is true, the plus and the minus buttons appear next to each field that lets the user add/remove the fields.
    • *
  • datetime, datetime-local, email, month, search, tel, time, url, week - HTML5 input fields types. Some browsers do not support these.
    • vReadOnly - ( optional, boolean|array ) if this is set to true, the readonly attribute will be inserted into the field input tag.
    • vSize - ( optional, integer|array ) the number that indicates the size of the input field.
    • vMaxLength - ( optional, integer|array ) the number that indicates the maxlength attribute of the input field.
  • number, range - HTML5 input field types. Some browsers do not support these.
    • vReadOnly - ( optional, boolean|array ) if this is set to true, the readonly attribute will be inserted into the field input tag.
    • vSize - ( optional, integer|array ) the number that indicates the size attribute of the input field.
    • vMax - ( optional, integer|array ) the number that indicates the max attribute of the input field.
    • vMin - ( optional, integer|array ) the number that indicates the min attribute of the input field.
    • vStep - ( optional, integer|array ) the number that indicates the step attribute of the input field.
    • vMaxLength - ( optional, integer|array ) the number that indicates the maxlength attribute of the input field.
    • fRepeatable - [2.1.3+]( optional, boolean|array ) whether the fields should be repeatable. If is true, the plus and the minus buttons appear next to each field that lets the user add/remove the fields.
  • textarea - a textarea input field. The following array keys are supported.
    • vReadOnly - ( optional, boolean|array ) if this is set to true, the readonly attribute will be inserted into the field input tag.
    • vRows - ( optional, integer|array ) the number of rows of the textarea field.
    • vCols - ( optional, integer|array ) the number of cols of the textarea field.
    • vMaxLength - ( optional, integer|array ) the number that indicates the maxlength attribute of the input field.
    • vRich - [2.1.2+]( optional, array ) 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.
    • fRepeatable - [2.1.3+]( optional, boolean|array ) whether the fields should be repeatable. If is true, the plus and the minus buttons appear next to each field that lets the user add/remove the fields. It's not supported for the rich editor.
  • radio - a radio button input field.
  • checkbox - a check box input field.
  • select - a dropdown input field.
    • vMultiple - ( optional, boolean|array ) 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.
    • vWidth - ( optional, string|array ) the width of the dropdown list including the unit. e.g. 120px
    • vSize - ( optional, integer|array ) the number that indicates the size attribute of the input field.
  • size - a size input field. This is a combination of number and select fields.
    • vSizeUnits - ( 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' )
    • vMultiple - ( optional, boolean|array ) 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.
    • vWidth - ( optional, string|array ) the width of the dropdown list including the unit. e.g. 120px
    • vReadOnly - ( optional, boolean|array ) if this is set to true, the readonly attribute will be inserted into the field input tag.
    • vSize - ( optional, integer|array ) the number that indicates the size attribute of the number input field.
    • vUnitSize - [2.1.5+]( optional, integer|array ) the number that indicates the size attribute of the select(unit) input field.
    • vMax - ( optional, integer|array ) the number that indicates the max attribute of the input field.
    • vMin - ( optional, integer|array ) the number that indicates the min attribute of the input field.
    • vStep - ( optional, integer|array ) the number that indicates the step attribute of the input field.
    • vMaxLength - ( optional, integer|array ) the number that indicates the maxlength attribute of the input field.
    • vSize - ( optional, integer|array ) the number that indicates the size attribute of the input field.
  • hidden - a hidden input field.
  • file - a file upload input field.
    • vAcceptAttribute - ( optional, string|array ) the accept attribute value. Default: audio/*|video/*|image/*|MIME_type
  • submit - a submit button input field.
    • vLink - ( optional, string|array ) the url(s) linked to the submit button.
    • vRedirect - ( optional, string|array ) the url(s) redirected to after submitting the input form.
    • vReset - [2.1.2+] ( optional, string|array ) the option key to delete. Set 1 for the entire option.
  • import - an inport input field. This is a custom file and submit field.
    • vAcceptAttribute - ( optional, string|array ) the accept attribute value. Default: audio/*|video/*|image/*|MIME_type
    • vClassAttributeUpload - ( optional, string|array ) [2.1.5+] the class attribute for the file upload field. Default: import
    • vImportOptionKey - ( optional, string|array ) the option table key to save the importing data.
    • vImportFormat - ( optional, string|array ) the import format. json, or array is supported. Default: array
    • vMerge - ( optional, boolean|array ) [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.
    • vExportFileName - ( optional, string|array ) the file name to download.
    • vExportFormat - ( optional, string|array ) the format type. array, json, or text is supported. Default: array.
    • vExportData - ( optional, string|array|object ) the data to export.
  • image - an image input field. This is a custom text field with an attached JavaScript script.
    • vReadOnly - ( optional, boolean|array ) if this is set to true, the readonly attribute will be inserted into the field input tag.
    • vSize - ( optional, integer|array ) the number that indicates the size of the input field.
    • vMaxLength - ( optional, integer|array ) the number that indicates the maxlength attribute of the input field.
    • vImagePreview - ( optional, boolean|array ) if this is set to false, the image preview will be disabled.
    • strTickBoxTitle - ( optional, string ) the text label displayed in the media uploader box's title.
    • strLabelUseThis - ( optional, string ) the text label displayed in the button of the media uploader to set the image.
    • fRepeatable - [2.1.3+] ( optional, boolean|array ) whether the fields should be repeatable. If is true, the plus and the minus buttons appear next to each field that lets the user add/remove the fields.
    • arrCaptureAttributes - [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. 'arrCaptureAttributes' => array( 'id', 'caption', 'description' )
    • fAllowExternalSource - [2.1.3+] ( optional, boolean ) whether external URL can be set via the uploader.
  • media - [2.1.3+] a media input field. This is a custom text field with an attached JavaScript script.
    • vReadOnly - ( optional, boolean|array ) if this is set to true, the readonly attribute will be inserted into the field input tag.
    • vSize - ( optional, integer|array ) the number that indicates the size of the input field.
    • vMaxLength - ( optional, integer|array ) the number that indicates the maxlength attribute of the input field.
    • strTickBoxTitle - ( optional, string ) the text label displayed in the media uploader box's title.
    • strLabelUseThis - ( optional, string ) the text label displayed in the button of the media uploader to set the image.
    • fRepeatable - [2.1.3+] ( optional, boolean|array ) whether the fields should be repeatable. If is true, the plus and the minus buttons appear next to each field that lets the user add/remove the fields.
    • arrCaptureAttributes - [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. 'arrCaptureAttributes' => array( 'id', 'caption', 'description' )
    • fAllowExternalSource - [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.
    • vReadOnly - ( optional, boolean|array ) if this is set to true, the readonly attribute will be inserted into the field input tag.
    • vSize - ( optional, integer|array ) the number that indicates the size of the input field.
    • vMaxLength - ( optional, integer|array ) the number that indicates the maxlength attribute of the input field.
    • fRepeatable - [2.1.3+] ( optional, boolean|array ) whether the fields should be repeatable. If is true, the plus and the minus buttons appear next to each field that lets the user add/remove the fields.
  • 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.
    • vTaxonomySlug - ( optional, string|array ) the taxonomy slug to list.
    • strWidth - ( optional, string ) the inline style property value of max-width of this element. Include the unit such as px, %. Default: 100%
    • strHeight - ( optional, string ) the inline style property value of height of this element. Include the unit such as px, %. Default: 250px
  • posttype - a posttype check list. This is a set of check boxes listing post type slugs.
    • arrRemove - ( optional, array ) the post type slugs not to be listed. e.g.array( 'revision', 'attachment', 'nav_menu_item' )

Example

$this->addSettingFields( array( // Single text field 'strFieldID' => 'text', 'strSectionID' => 'text_fields', 'strTitle' => __( 'Text', 'admin-page-framework-demo' ), 'strDescription' => __( 'Type something here.', 'admin-page-framework-demo' ), // additional notes besides the form field 'strType' => 'text', 'numOrder' => 1, 'vDefault' => 123456, 'vSize' => 40, ), array( // Multiple text fields 'strFieldID' => 'text_multiple', 'strSectionID' => 'text_fields', 'strTitle' => 'Multiple Text Fields', 'strDescription' => 'These are multiple text fields.', // additional notes besides the form field 'strType' => 'text', 'numOrder' => 2, 'vDefault' => array( 'Hello World', 'Foo bar', 'Yes, we can.' ), 'vLabel' => array( 'First Item: ', 'Second Item: ', 'Third Item: ' ), 'vSize' => array( 30, 60, 90, ), ) );

Parameters

array $arrField1

the field array.

array $arrField2

( optional ) another field array.

array $_and_more

( optional ) add more field arrays to the next parameters as many as necessary.

addSettingField()

addSettingField( $arrField) : void

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

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

Parameters

$arrField

removeSettingFields()

removeSettingFields(string $strFieldID1, string $strFieldID2, string $_and_more) : void

Removes the given field(s) by field ID.

This accesses the property storing the added field arrays and removes the specified ones.

Example

$this->removeSettingFields( 'fieldID_A', 'fieldID_B', 'fieldID_C', 'fieldID_D' );

Parameters

string $strFieldID1

the field ID to remove.

string $strFieldID2

( optional ) another field ID to remove.

string $_and_more

( optional ) add more field IDs to the next parameters as many as necessary.

getFieldErrors()

getFieldErrors( $strPageSlug,  $fDelete)

Retrieves the settings error array set by the user in the validation callback.

Parameters

$strPageSlug
$fDelete

setFieldErrors()

setFieldErrors(array $arrErrors, string $strID, integer $numSavingDuration)

Sets the field error array.

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

Example

public function validation_first_page_verification( $arrInput, $arrOldPageOptions ) { // valication_ + page slug + _ + tab slug $fVerified = true; $arrErrors = array(); // Check if the submitted value meets your criteria. As an example, here a numeric value is expected. if ( isset( $arrInput['first_page']['verification']['verify_text_field'] ) && ! is_numeric( $arrInput['first_page']['verification']['verify_text_field'] ) ) { // Start with the section key in $arrErrors, not the key of page slug. $arrErrors['verification']['verify_text_field'] = 'The value must be numeric: ' . $arrInput['first_page']['verification']['verify_text_field']; $fVerified = false; } // An invalid value is found. if ( ! $fVerified ) { // Set the error array for the input fields. $this->setFieldErrors( $arrErrors ); $this->setSettingNotice( 'There was an error in your input.' ); return $arrOldPageOptions; } return $arrInput; }

Parameters

array $arrErrors

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

string $strID

this should be the page slug of the page that has the dealing form field.

integer $numSavingDuration

the transient's lifetime. 300 seconds means 5 minutes.

getFieldValue()

getFieldValue( $strFieldNameToFind)

Retrieves the specified field value stored in the options.

Useful when you don't know the section name but it's a bit slower than accessing the property value by specifying the section name.

Parameters

$strFieldNameToFind

setRootMenuPage()

setRootMenuPage(string $strRootMenuLabel, string $strURLIcon16x16, string $intMenuPosition) : void

Sets to which top level page is going to be adding sub-pages.

Example

$this->setRootMenuPage( 'Settings' ); $this->setRootMenuPage( 'APF Form', plugins_url( 'image/screen_icon32x32.jpg', FILE ) );

Parameters

string $strRootMenuLabel

If the method cannot find the passed string from the following listed items, it will create a top level menu item with the passed string. ( case insensitive )

Dashboard, Posts, Media, Links, Pages, Comments, Appearance, Plugins, Users, Tools, Settings, Network Admin
string $strURLIcon16x16

( optional ) the URL or the file path of the menu icon. The size should be 16 by 16 in pixel.

string $intMenuPosition

( optional ) the position number that is passed to the $position parameter of the add_menu_page() function.

setRootMenuPageBySlug()

setRootMenuPageBySlug(string $strRootMenuSlug) : void

Sets the top level menu page by page slug.

The page should be already created or scheduled to be created separately.

Example

$this->setRootMenuPageBySlug( 'edit.php?post_type=apf_posts' );

Parameters

string $strRootMenuSlug

The page slug of the top-level root page.

addSubMenuPage()

addSubMenuPage(string $strPageTitle, string $strPageSlug, string $strScreenIcon, string $strCapability, integer $numOrder, boolean $fShowPageHeadingTab, boolean $fShowInMenu) : void

Adds a single sub-menu page.

Example

$this->addSubMenuPage( 'My Page', 'my_page', 'edit-pages' );

Parameters

string $strPageTitle

The title of the page.

string $strPageSlug

The slug of the page.

string $strScreenIcon

( optional ) Either a screen icon ID, a url of the icon, or a file path to the icon, with the size of 32 by 32 in pixel. The accepted icon IDs are as follows.

edit, post, index, media, upload, link-manager, link, link-category, edit-pages, page, edit-comments, themes, plugins, users, profile, user-edit, tools, admin, options-general, ms-admin, generic

Note: the generic ID is available since WordPress 3.5.

string $strCapability

( optional ) The access level to the page.

integer $numOrder

( optional ) the order number of the page. The lager the number is, the lower the position it is placed in the menu.

boolean $fShowPageHeadingTab

( optional ) If this is set to false, the page title won't be displayed in the page heading tab. Default: true.

boolean $fShowInMenu

( optional ) If this is set to false, the page title won't be displayed in the sidebar menu while the page is still accessible. Default: true.

showPageTitle()

showPageTitle(boolean $fShow,  $strPageSlug) : void

Sets whether the page title is displayed or not.

Example

$this->showPageTitle( false ); // disables the page title.

Parameters

boolean $fShow

If false, the page title will not be displayed.

$strPageSlug

showPageHeadingTabs()

showPageHeadingTabs(boolean $fShow, string $strPageSlug)

Sets whether page-heading tabs are displayed or not.

Example

$this->showPageHeadingTabs( false ); // disables the page heading tabs by passing false.

Parameters

boolean $fShow

If false, page-heading tabs will be disabled; otherwise, enabled.

string $strPageSlug

The page to apply the visibility setting. If not set, it applies to all the pages.

showInPageTabs()

showInPageTabs(boolean $fShow, string $strPageSlug)

Sets whether in-page tabs are displayed or not.

Sometimes, it is required to disable in-page tabs in certain pages. In that case, use the second parameter.

Parameters

boolean $fShow

If false, in-page tabs will be disabled.

string $strPageSlug

The page to apply the visibility setting. If not set, it applies to all the pages.

setInPageTabTag()

setInPageTabTag(string $strTag, string $strPageSlug)

Sets in-page tab's HTML tag.

Example

$this->setInPageTabTag( 'h2' );

Parameters

string $strTag

The HTML tag that encloses each in-page tab title. Default: h3.

string $strPageSlug

The page slug that applies the setting.

setPageHeadingTabTag()

setPageHeadingTabTag(string $strTag, string $strPageSlug)

Sets page-heading tab's HTML tag.

Example

$this->setPageHeadingTabTag( 'h2' );

Parameters

string $strTag

The HTML tag that encloses the page-heading tab title. Default: h2.

string $strPageSlug

The page slug that applies the setting.

addInPageTab()

addInPageTab(string $strPageSlug, string $strTabTitle, string $strTabSlug, integer $numOrder, boolean $fHide, string $strParentTabSlug) : void

Adds an in-page tab.

Parameters

string $strPageSlug

The page slug that the tab belongs to.

string $strTabTitle

The title of the tab.

string $strTabSlug

The tab slug. Non-alphabetical characters should not be used including dots(.) and hyphens(-).

integer $numOrder

( optional ) the order number of the tab. The lager the number is, the lower the position it is placed in the menu.

boolean $fHide

( optional ) default: false. If this is set to false, the tab title will not be displayed in the tab navigation menu; however, it is still accessible from the direct URL.

string $strParentTabSlug

( optional ) this needs to be set if the above fHide is true so that the parent tab will be emphasized as active when the hidden page is accessed.

addInPageTabs()

addInPageTabs(array $arrTab1, array $arrTab2, array $_and_more) : void

Adds in-page tabs.

The parameters accept in-page tab arrays and they must have the following array keys.

In-Page Tab Array

  • strPageSlug - ( string ) the page slug that the tab belongs to.
  • strTabSlug - ( string ) the tab slug. Non-alphabetical characters should not be used including dots(.) and hyphens(-).
  • strTitle - ( string ) the title of the tab.
  • numOrder - ( optional, integer ) the order number of the tab. The lager the number is, the lower the position it is placed in the menu.
  • fHide - ( optional, boolean ) default: false. If this is set to false, the tab title will not be displayed in the tab navigation menu; however, it is still accessible from the direct URL.
  • strParentTabSlug - ( optional, string ) this needs to be set if the above fHide is true so that the parent tab will be emphasized as active when the hidden page is accessed.

Example

$this->addInPageTabs( array( 'strTabSlug' => 'firsttab', 'strTitle' => __( 'Text Fields', 'my-text-domain' ), 'strPageSlug' => 'myfirstpage' ), array( 'strTabSlug' => 'secondtab', 'strTitle' => __( 'Selectors and Checkboxes', 'my-text-domain' ), 'strPageSlug' => 'myfirstpage' ) );

Parameters

array $arrTab1

The in-page tab array.

array $arrTab2

Another in-page tab array.

array $_and_more

Add in-page tab arrays as many as necessary to the next parameters.

addHelpTab()

addHelpTab(array $arrHelpTab) : void

Adds the given contextual help tab contents into the property.

Contextual Help Tab Array Structure

  • strPageSlug - the page slug of the page that the contextual help tab and its contents are displayed.
  • strPageTabSlug - ( optional ) the tab slug of the page that the contextual help tab and its contents are displayed.
  • strHelpTabTitle - the title of the contextual help tab.
  • strHelpTabID - the id of the contextual help tab.
  • strHelpTabContent - the HTML string content of the the contextual help tab.
  • strHelpTabSidebarContent - ( optional ) the HTML string content of the sidebar of the contextual help tab.

Example

$this->addHelpTab( array( 'strPageSlug' => 'first_page', // ( mandatory ) // 'strPageTabSlug' => null, // ( optional ) 'strHelpTabTitle' => 'Admin Page Framework', 'strHelpTabID' => 'admin_page_framework', // ( mandatory ) 'strHelpTabContent' => __( 'This contextual help text can be set with the addHelpTab() method.', 'admin-page-framework' ), 'strHelpTabSidebarContent' => __( 'This is placed in the sidebar of the help pane.', 'admin-page-framework' ), ) );

Parameters

array $arrHelpTab

The help tab array. The key structure is explained in the description part.

setHelpTab()

setHelpTab( $strID,  $strTitle,  $arrContents,  $arrSideBarContents)

Sets the contextual help tab.

On contrary to other methods relating to contextual help tabs that just modify the class properties, this finalizes the help tab contents. In other words, the set values here will take effect.

Parameters

$strID
$strTitle
$arrContents
$arrSideBarContents

askResetOptions()

askResetOptions( $strPressedFieldName,  $strPageSlug)

Displays a confirmation message to the user when a reset button is pressed.

Parameters

$strPressedFieldName
$strPageSlug

resetOptions()

resetOptions( $strKeyToReset,  $arrInput)

Performs reset options.

Parameters

$strKeyToReset
$arrInput

setRedirectTransients()

setRedirectTransients( $strURL)

Parameters

$strURL

getPressedCustomSubmitButtonSiblingValue()

getPressedCustomSubmitButtonSiblingValue( $arrPostElements,  $strTargetKey) : mixed

Retrieves the target key's value associated with the given data to a custom submit button.

This method checks if the associated submit button is pressed with the input fields.

Parameters

$arrPostElements
$strTargetKey

Returns

mixed —

Returns null if no button is found and the associated link url if found. Otherwise, the URL associated with the button.

importOptions()

importOptions( $arrStoredOptions,  $strPageSlug,  $strTabSlug)

Processes the imported data.

Parameters

$arrStoredOptions
$strPageSlug
$strTabSlug

exportOptions()

exportOptions( $vData,  $strPageSlug,  $strTabSlug)

Parameters

$vData
$strPageSlug
$strTabSlug

getFilteredOptions()

getFilteredOptions( $arrInput,  $strPageSlug,  $strTabSlug,  $strPressedFieldID,  $strPressedInputID) : array

Apples validation filters to the submitted input data.

Parameters

$arrInput
$strPageSlug
$strTabSlug
$strPressedFieldID
$strPressedInputID

Returns

array —

The filtered input array.

getPageOptions()

getPageOptions( $strPageSlug) : array

Retrieves the stored options of the given page slug.

Other pages' option data will not be contained in the returning array. This is used to pass the old option array to the validation callback method.

Parameters

$strPageSlug

Returns

array —

the stored options of the given page slug. If not found, an empty array will be returned.

getOtherTabOptions()

getOtherTabOptions( $strPageSlug,  $arrSectionKeysForTheTab) : array

Retrieves the stored options excluding the currently specified tab's sections and their fields.

This is used to merge the submitted form data with the previously stored option data of the form elements that belong to the in-page tab of the given page.

Parameters

$strPageSlug
$arrSectionKeysForTheTab

Returns

array —

the stored options excluding the currently specified tab's sections and their fields. If not found, an empty array will be returned.

getOtherPageOptions()

getOtherPageOptions( $strPageSlug) : array

Retrieves the stored options excluding the key of the given page slug.

This is used to merge the submitted form input data with the previously stored option data except the given page.

Parameters

$strPageSlug

Returns

array —

the array storing the options excluding the key of the given page slug.

getPageSlugBySectionID()

getPageSlugBySectionID( $strSectionID) : string|null

Retrieves the page slug that the settings section belongs to.

Parameters

$strSectionID

Returns

string|null

setFieldHeadTagElements()

setFieldHeadTagElements( $arrField)

Sets the given field type's enqueuing scripts and styles.

A helper function for the above registerSettings() method.

Parameters

$arrField

formatSectionArrays()

formatSectionArrays( $arrSections)

Formats the given section arrays.

Parameters

$arrSections

isSettingSectionOfCurrentTab()

isSettingSectionOfCurrentTab( $arrSection) : boolean

Checks if the given section belongs to the currently loading tab.

Parameters

$arrSection

Returns

boolean —

Returns true if the section belongs to the current tab page. Otherwise, false.

formatFieldArrays()

formatFieldArrays( $arrFields)

Formats the given field arrays.

Parameters

$arrFields

registerRootMenuPage()

registerRootMenuPage()

Registers the root menu page.

registerSubMenuPage()

registerSubMenuPage( $arrArgs)

Registers the sub-menu page.

Parameters

$arrArgs

getScreenIcon()

getScreenIcon( $strPageSlug)

Retrieves the screen icon output as HTML.

Parameters

$strPageSlug

getScreenIDAttribute()

getScreenIDAttribute( $oScreen)

Retrieves the screen ID attribute from the given screen object.

Parameters

$oScreen

getPageHeadingTabs()

getPageHeadingTabs( $strCurrentPageSlug,  $strTag,  $arrOutput) : string

Retrieves the output of page heading tab navigation bar as HTML.

Parameters

$strCurrentPageSlug
$strTag
$arrOutput

Returns

string —

the output of page heading tabs.

getInPageTabs()

getInPageTabs( $strCurrentPageSlug,  $strTag,  $arrOutput) : string

Retrieves the output of in-page tab navigation bar as HTML.

Parameters

$strCurrentPageSlug
$strTag
$arrOutput

Returns

string —

the output of in-page tabs.

getParentTabSlug()

getParentTabSlug( $strPageSlug,  $strTabSlug) : string

Retrieves the parent tab slug from the given tab slug.

Parameters

$strPageSlug
$strTabSlug

Returns

string —

the parent tab slug.