Methods

SetUp()

Triggered by the admin_menu hook. Your initial setups should be defined in this method. To perform certain tasks prior to this method, use the start_ + extended class name hook that is triggered at the end of the class constructor.

SetRootMenu( $strRootMenu, $strPathIcon16x16=null )

Determines to which top level page is going to be adding sub-pages. Only one root page can be set per one class instance.

Parameters

  • $strRootMenu – String. If the method cannot find the passed string from the following listed ones, it will create a top level menu item with that name. ( case insensitive )
    • Dashboard
    • Posts
    • Media
    • Links
    • Pages      
    • Comments       
    • Appearance   
    • Plugins       
    • Users           
    • Tools           
    • Settings       
    • Network Admin   
  • $strPathIcon16x16 – ( optional )  String. The URL of the menu icon. The size should be 16 by 16 in pixel.

SetRootMenuBySlug( $strSlug )

Sets the parent menu by page slug. This is useful when adding pages to an existing plugin top level menu.

Parameters

  • $strSlug – String. The slug name of the parent menu to which sub pages are going to be added.

AddSubMenu( $strSubTitle, $strPageSlug, $strPathIcon32x32=null )

Adds sub menus and pages to the specified parent page set by the SetRootMenu() method.

Parameters

  • $strSubTitle – String. The adding sub-page’s title.
  • $strPageSlug – String. The adding sub-page’s page slug. Avoid using dots(.) and hyphens(-) since this plug will be used by the callback function names.
  • $strPathIcon32x32 – ( optional ) – String. The screen icon which appears at the top of the page.

AddFormSections( $arrSections )

Adds form sections of Settings API.

Parameters

  • $arrSections – Array. The associative array containing the information of sections with the following keys. For more information, see the Section Array section below.

Section Array

The associative array with the following keys need to be passed to the first parameter of the AddFormSections() method.

  • pageslug – String. Specifies to which page the form section is going to be adding.
  • tabslug – ( conditional ) String. Specifies to which tab the form section is going to be adding. This is only effective if in-page tabs are created in the page specified by the above page slug.
  • id – String. The section ID. Set a unique string ID consisting of alphabets, numbers and underscores. This ID is used by the callback function names.
  • title – ( optional ) String. The string displayed at the top of the fields.
  • description – ( optional ) String. The string to be displayed below the title.
  • fields – Array. The array containing field information, consisting of arrays with the following keys. For more information, see the Field Array section below.
  • capability – [1.0.2.1+] ( optional ) String. the WordPress capability. The section will be invisible if the user does not have enough access level for the set capability.
  • if – [1.0.4.1+] ( optional ) Boolean. The true or false value that sets a condition of the section’s visibility.

Field Array

An associative array with the following keys need to be passed to the fields key of the section array.

  • id – The filed id. String. This must be set to add a field. Set a unique string ID consisting of alphabets, numbers and underscores. This ID is used by the callback function names.
  • type – String. The type of the input field. For more information, see the Field Types section below.
  • title – ( optional ) String. The field title string displayed at the left of the setting table.  
  • tip – ( optional ) String. The description text that appears on mouse hover on the field title.  If not set, the value set to the description key will be used.
  • description – ( optional ) String. The description text that appears below each field.
  • error – ( optional ) String. The error message that appears when validation fails. The validation callback method needs to be defined in order to show this message. For the import type, when import fails it will be displayed. Some field types do not support this.
  • class ( optional ) – String. the class attribute inserted into the field tag. This is useful to set a custom CSS style such as submit buttons with the ‘button-secondary’ class.
  • default – ( optional ) String. Sets the default value. Some field types do not support this.
  • value ( optional ) – String. If this is set, it overrides the default key. This is useful to display values which are not the ones that the framework automatically saves into the database.
  • disable ( optional ) – Boolean ( True/False ). This indicates whether the input field should be disabled by inserting disabled=”Disabled” into the input tab.
  • pre_html ( optional ) – String. The HTML code inserted before the field tag and the description.
  • post_html ( optional ) – String. The HTML code inserted after the field tag and the description.
  • pre_field – [1.0.3+] ( optional ) – String. The HTML code inserted right before the field tag.
  • post_field – [1.0.3+] ( optional ) – String. The HTML code inserted right after the field tag.
  • delimiter – [1.0.2+] ( optional ) String. The string that delimits multiple fields. Some field types do not support this.
  • capability – [1.0.2.1+] ( optional ) String. The WordPress capability. The input filed will be invisible if the user does not have the enough access level for the set capability.
  • name – [1.0.3+] ( optional ) String. The field name attribute to assign in stead of the one the framework automatically assigns based on the option key, page slug, section ID and field ID.
  • if – [1.0.4.1+] ( optional ) Boolean. The true or false value that sets a condition of the field’s visibility.

Field Types

The following types are supported:

  • text, password, color, date, datetime, datetime-local, email, month, search, tel, time, url, week, number, range – rectangular text field box.
  • textarea – rectangular text field box with columns and rows. The sizes of column and rows can be set with the cols and rows key.
  • radio – radio buttons.
  • checkbox – check box(es).
  • select – a pull-down list.
  • submit – a submit button.
  • hidden – a hidden field.
  • file – a file field. This is mostly used for uploading a file. If this is set, the enctype attribute of the form tag will be set to ‘multipart/form-data‘.
  • import – an upload button that imports a setting file into the option database table. Set the label key for the button text. For error message, use the error key and update message, use the update_message key.
  • export – a button that starts downloading the exported option file when it is pressed. Set the label key for the button text.
  • image – an image upload field.

text, password, color, date, datetime, datetime-local, email, month, search, tel, time, url, week, number, range

Keys supported by these field types:

  • size – ( optional ) Whole number.  Determines the size of the text field.
  • default – ( optional ) String. Sets the default value.
  • readonly – [+1.0.3] ( optional ) Boolean ( True/False )  If this is true, it adds the readonly attribute to the input field.

number, range

Keys supported by these field types:

  • size – ( optional ) Whole number.  Determines the size of the text field.
  • default – ( optional ) String. Sets the default value.
  • step – ( optional ) Whole number.  Determines the step of the number set in the input field.

textarea

Keys supported by this field type:

  • cols – ( optional ) – Whole number. Determines the number of columns of the text area field.
  • rows – ( optional ) – Whole number. Determines the number of rows of the text area field.
  • default – ( optional ) String. Sets the default value.
  • readonly – [1.0.3+] ( optional ) Boolean ( True/False )  If this is true, it adds the readonly attribute to the input field.

radio, select

Keys supported by these field types:

  • label – Array. Pass the numerically indexed array containing the strings of label. e.g. array( ‘apple’, ‘banana’, ‘cherry’ )
  • default – ( optional ) Array. Sets the default value. Pass the array corresponding to the array passed to the above label key.
  • delimiter – [1.0.2+] ( optional ) String. The string that delimits multiple fields. This is effective when an array is passed to the label key. The select field type does not support this. e.g. &nbsp; Default: <br />

checkbox

Keys supported by this field type:

  • labelString or Array. Pass the single string of label for a single field. Or pass a numerically indexed array containing the strings of label for multiple checkboxes.
  • default – ( optional ) String or Array. Sets the default value. Pass a string if the above label  is assigned a string; otherwise, pass an array corresponding to the array passed to the above label key.
  • delimiter – [1.0.2+] ( optional ) String. The string that delimits multiple fields. This is effective when an array is passed to the label key. e.g. &nbsp; Default: <br />

submit, hidden, file

Keys supported by these field types:

  • label – String or Array. Pass the single string of label for a single field. Or pass a numerically indexed array containing the strings of label for multiple fields.
  • delimiter – [1.0.2+] ( optional ) String. The string that delimits multiple fields. This is effective when an array is passed to the label key. The hidden field type does not support this. e.g. &nbsp; Default: <br />
  • href – [1.0.3+] ( optional ) String. The URL to be redirected after the user presses the button. The settings will not be saved.

import

Keys supported by these field types:

  • label – String. Pass the single string for the button label. If not set, “Import Options” will be set.
  • delimiter – [1.0.2+]( optional ) String. The string that delimits the file uploading field and the submit button. e.g. &nbsp; Default: <br />

export

Keys supported by these field types:

  • label – String or Array. Pass the single string for the button label. Or pass a numerically indexed array containing the strings of label for multiple export buttons.  If not set, “Export Options” will be set.
  • file_name – String or Array. Pass the single string for the exporting file name. Or pass a numerically indexed array corresponding to the array set to the label key. The file names should have the .txt file extension.
  • delimiter – ( optional ) String. The string that delimits multiple fields. This is effective when an array is passed to the label key for the export type. e.g. &nbsp; Default: <br />

image

Keys supported by this field type:

  • style – String. CSS styles applied to the div tag of the image preview element. Default: min-height: 100px;
  • default – ( optional ) String. The URL of the image.
  • label – ( optional ) Array. Pass an associative array with the following listed keys.
    • title – String. The title of the thick box window which pop ups when the upload button is pressed.
    • insert – String. The button label to set the image after selecting one.
    • upload – String. The button label for the image upload. 
    • unset – String. The button label for unsetting the image.
    • delete – String. The button label for deleting the image.
  • visibility – ( optional ) Array. Pass an associative array with the following listed keys.
    • preview – Boolean (True/False). Set True to make the image preview visible; otherwise, set to False.
    • image_url – Boolean (True/False). Set True to make the image url below the preview image visible; otherwise, set to False.
    • unset_button – Boolean (True/False). Set True to make the unset button visible; otherwise, set to False.
    • delete_button – Boolean (True/False). Set True to make the delete button visible; otherwise, set to False.

Example

AddInPageTabs( $strSubPageSlug, $arrTabs )

Adds in-page tabs which appears at the top of the page below the page heading title. In-page tabs are different from page tabs and are displayed smaller than page tabs.

Parameters

  • $strSubPageSlug – String. The sub page’s page slug. Avoid using dots(.) and hyphens(-) since this plug will be used by the callback function names.
  • $arrTabs – Array. The array that stores the information of tab pages with the key of page slug and the value of page title.

Example

ShowPageHeadingTabs( $bShowPageHeadingTabs )

Sets whether the page heading tabs should appear.

Parameters

  • $bShowPageHeadingTabs – True / False. Set True to show; otherwise, false.

AddLinkToPluginDescription( $vLinks )

Adds the link(s) to the plugin description column in the plugin listing page.

Parameters

  • $vLinks – Either the numerically indexed array of links or the single text link.

Example

AddLinkToPluginTitle( $vLinks )

Adds the link(s) to the plugin title column in the plugin listing page.

Parameters

  • $vLinks – Either the numerically indexed array of links or the single text link.

Example

Leave a Reply

Your email address will not be published. Required fields are marked *