\AdminPageFramework_MetaBox

Provides methods for creating meta boxes.

Hooks

The class automatically creates WordPress action and filter hooks associated with the class methods. The class methods corresponding to the name of the below actions and filters can be extended to modify the page output. Those methods are the callbacks of the filters and actions.

Methods and Action Hooks

  • start_ + extended class name – triggered at the end of the class constructor.

Methods and Filter Hooks

  • extended class name + _ + field_ + field ID – receives the form input field output of the given input field ID. The first parameter: output string. The second parameter: the array of option.
  • style_ + extended class name – receives the output of the CSS rules applied to the pages of the associated post types with the meta box.
  • script_ + extended class name – receives the output of the JavaScript scripts applied to the pages of the associated post types with the meta box.
  • validation_ + extended class name – receives the form submission values as array. The first parameter: submitted input array. The second parameter: the original array stored in the database.

Remarks

The slugs must not contain a dot(.) or a hyphen(-) since it is used in the callback method name.

Summary

Methods
Properties
Constants
__construct()
replyToLoadDefaultFieldTypeDefinitions()
setUp()
removeMediaLibraryTab()
replaceThickBoxText()
addMetaBox()
echoMetaBoxContents()
saveMetaBoxFields()
__call()
No public properties found
No constants found
addSettingFields()
addSettingField()
addHelpText()
addHelpTextForFormFields()
setHelpTab()
$oScreen
N/A
setFieldHeadTagElements()
setOptionArray()
getFieldOutput()
No private properties found
N/A

Properties

$oScreen

$oScreen : object

Stores the screen object.

Type

object

Methods

__construct()

__construct(string $strMetaBoxID, string $strTitle, string|array $vPostTypes, string $strContext, string $strPriority, string $strCapability, string $strTextDomain) : void

Constructs the class object instance of AdminPageFramework_MetaBox.

Parameters

string $strMetaBoxID

The meta box ID.

string $strTitle

The meta box title.

string|array $vPostTypes

( optional ) The post type(s) that the meta box is associated with.

string $strContext

( optional ) The part of the page where the edit screen section should be shown ('normal', 'advanced', or 'side') Default: normal.

string $strPriority

( optional ) The priority within the context where the boxes should show ('high', 'core', 'default' or 'low') Default: default.

string $strCapability

( optional ) The access level to the meta box. Default: edit_posts.

string $strTextDomain

( optional ) The text domain applied to the displayed text messages. Default: admin-page-framework.

replyToLoadDefaultFieldTypeDefinitions()

replyToLoadDefaultFieldTypeDefinitions()

Loads the default field type definition.

setUp()

setUp() : void

The method for all necessary set-ups.

Example

public function setUp() { $this->addSettingFields( array( 'strFieldID' => 'sample_metabox_text_field', 'strTitle' => 'Text Input', 'strDescription' => 'The description for the field.', 'strType' => 'text', ), array( 'strFieldID' => 'sample_metabox_textarea_field', 'strTitle' => 'Textarea', 'strDescription' => 'The description for the field.', 'strType' => 'textarea', 'vDefault' => 'This is a default text.', ) ); }

removeMediaLibraryTab()

removeMediaLibraryTab( $arrTabs)

since 2.1.3

Parameters

$arrTabs

replaceThickBoxText()

replaceThickBoxText( $strTranslated,  $strText)

Replaces the label text of a button used in the media uploader.

Parameters

$strTranslated
$strText

addMetaBox()

addMetaBox() : void

Adds the defined meta box.

echoMetaBoxContents()

echoMetaBoxContents(object $oPost, array $vArgs) : void

Echoes the meta box contents.

Parameters

object $oPost

The object of the post associated with the meta box.

array $vArgs

The array of arguments.

saveMetaBoxFields()

saveMetaBoxFields( $intPostID)

Saves the meta box field data to the associated post.

Parameters

$intPostID

__call()

__call( $strMethodName,  $arrArgs)

Parameters

$strMethodName
$arrArgs

addSettingFields()

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

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

Example

$this->addSettingFields( array( 'strFieldID' => 'sample_metabox_text_field', 'strTitle' => 'Text Input', 'strDescription' => 'The description for the field.', 'strType' => 'text', ), array( 'strFieldID' => 'sample_metabox_textarea_field', 'strTitle' => 'Textarea', 'strDescription' => 'The description for the field.', 'strType' => 'textarea', 'vDefault' => 'This is a default text.', ) );

Parameters

array $arrField1

The field array.

array $arrField2

Another field array.

array $_and_more

Add more fields arrays as many as necessary to the next parameters.

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

addHelpText()

addHelpText( $strHTMLContent,  $strHTMLSidebarContent)

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

Parameters

$strHTMLContent
$strHTMLSidebarContent

addHelpTextForFormFields()

addHelpTextForFormFields( $strFieldTitle,  $strHelpText,  $strHelpTextSidebar)

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. On contrary to the addHelpTab() method of the AdminPageFramework_Help class, the help tab title is already determined and the meta box ID and the title will be used.

Parameters

$strFieldTitle
$strHelpText
$strHelpTextSidebar

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

setFieldHeadTagElements()

setFieldHeadTagElements( $arrField)

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

A helper function for the above registerSettings() method.

Parameters

$arrField

setOptionArray()

setOptionArray( $intPostID,  $arrFields)

Parameters

$intPostID
$arrFields

getFieldOutput()

getFieldOutput( $arrField)

Parameters

$arrField