开发者 |
Michael Uno
miunosoft pcraig3 |
---|---|
更新时间 | 2022年4月15日 11:48 |
捐献地址: | 去捐款 |
PHP版本: | 3.4 及以上 |
WordPress版本: | 5.9.3 |
版权: | GPLv2 or later |
版权网址: | 版权信息 |
text
- a normal field to enter text input.password
- a masked text input field.textarea
- a text input field with multiple lines. It supports TinyMCE 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 an image URL.media
- a custom text field with the media uploader script that lets the user set a 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 set of check-lists of taxonomies enabled on the site in a tabbed box.taxonomy
- 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
- a text field placed in the section title to let the user name the section.system
- displays the site system information.inline_mixed
- consists of inline elements of fields with different field types.sample
- a sample custom field type with a JavaScript script.github
- displays GitHub buttons.path
- lets the user select file paths on the server.toggle
- lets the user toggle a switch button.no_ui_slider
- lets the user set values between ranges with a slider.select2
- lets the user select items from a predefined list which cam be populated with AJAX.post_type_taxonomy
- lets the user select taxonomy terms of selected post types.add_submenu_page()
function to register sub menu pages. When the same page slug is registered for multiple root pages, only the last registered callback gets triggered. The other ones will be ignored.
This means if you choose a very simple page slug such as about
for your plugin/theme's information page and then if there is another plugin using the same page slug, your users will get either of your page or the other.
To avoid this, make sure to use a unique page slug. One way to do that is to add a prefix like apf_about
.
Use the files generated with the component generator
There is one thing you need to be careful when you include the framework: the framework version conflicts. Imagine you publish a plugin using the framework v3.4.6 and your plugin user installs a plugin using the framework v3.0.0 which is below your framework version. If the other plugin loads earlier than yours, your plugin may not work properly and vice versa.
There is a way to avoid such a conflict: change the PHP class names of the framework you include. All the class names have the prefix AdminPageFramework
so just change it to something like MyPlugin_AdminPageFramework
.
Go to Dashboard -> Admin Page Framework -> Tools -> Generator. Set the prefix in the option field and download the files.
If you do not modify the framework class names, you are supposed to extend the AdminPageFramework
factory class.
class MyAdminPage extends AdminPageFramework { ... }
When you modify the framework class names, make sure you extend the class with the modified name.
class MyAdminPage extends MyPlugin_AdminPageFramework { ... }
For more detailed instruction, go to Dashboard -> Admin Page Framework -> About -> Getting Started.
By the time WordPress's minimum required PHP version becomes 5.3 or higher, we can use name spaces then this problem will be solved.
Change Framework's System Messages
The default messages defined by the framework can be changed. For example, when you import a setting with the framework, the setting notice "The options have been updated." will be displayed.
If you want to change it to something else, modify the oMsg
object. It has the aMessages
public property array holding all the messages that the framework uses.
Get comfortable with the 'attributes' array argument
In each field definition array, you can set the attributes
arguments which defines the HTML attributes of the field so that you can modify the output of the field by passing attribute values.
The argument accepts the values as an array. Each element represents the attribute's name and value. The array key corresponds to the name of the attribute and the value to the attribute value.
For example,
array( 'field_id' => 'interval', 'title' => __( 'Interval', 'task-scheduler' ), 'type' => 'number', 'attributes' => array( 'min' => 0, 'step' => 1, 'max' => 24, ), ),
In addition, you can change the attributes of the following container elements by setting their key and passing a nested attribute array.
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.array( 'field_id' => 'submit', 'type' => 'submit', 'save' => false, 'value' => __( 'Save', 'task-scheduler' ), 'label_min_width' => 0, 'attributes' => array( 'field' => array( 'style' => 'float:right; clear:none; display: inline;', ), ), )
For meta box and widget form fields (as they have slightly different styling than generic admin pages),
array( 'field_id' => 'submit_in_meta_box', 'type' => 'submit', 'save' => false, 'show_title_column' => false, 'label_min_width' => 0, 'attributes' => array( 'field' => array( 'style' => 'float:right; width:auto;', ), ), ),
Change Preview Image Size of the 'image' Field Type
To specify a custom size to the preview element of the image
field type, set an attribute array like the below, where 300px is the max width.
array( 'field_id' => 'my_image_field_id', 'title' => __( 'Image', 'admin-page-framework-demo' ), 'type' => 'image', 'attributes' => array( 'preview' => array( 'style' => 'max-width: 200px;', ), ), ),
Display items of 'radio' field type one per line
To display radio button items one per line, set the label_min_width
to 100%
.
array( 'field_id' => 'my_radio_field_id', 'title' => __( 'Radio Button', 'admin-page-framework-demo' ), 'type' => 'radio', 'label_min_width' => '100%', 'label' => array( 'a' => __( 'This is a.', 'admin-page-framework-demo' ), 'b' => __( 'This is b.', 'admin-page-framework-demo' ), 'c' => __( 'This is a.', 'admin-page-framework-demo' )c ), ),
Set default field value
To set the initial value of a field, use the default
argument in the field definition array.
array( 'field_id' => 'my_text_field_id', 'title' => __( 'My Text Input Field', 'admin-page-framework-demo' ), 'type' => 'text', 'default' => 'This text will be displayed for the first time that the field is displayed and will be overridden when a user set an own value.', ),
Always display a particular value in a field
The value
argument in the definition array can suppress the saved value. This is useful when you want to set a value from a different data source or create a wizard form that stores the data in a custom location.
array( 'field_id' => 'my_text_field_id', 'title' => __( 'My Text Input Field', 'admin-page-framework-demo' ), 'type' => 'text', 'value' => 'This will be always set.', ),
If it is a repeatable field, set values in numerically indexed sub-elements.
array( 'field_id' => 'my_text_field_id', 'title' => __( 'My Text Input Field', 'admin-page-framework-demo' ), 'type' => 'text', 'repeatable' => true, 'value' => 'the first value', array( 'value' => 'the second value', ), array( 'value' => 'the third value', ), ),
Alternately, you may use the options_{instantiated class name}
filter to suppress the options so that setting the value argument is not necessary.
See examples, https://gist.github.com/michaeluno/c30713fcfe0d9d45d89f, https://gist.github.com/michaeluno/fcfac27825aa8a35b90f,mime_types
argument for the image
and media
field types.setSettingNotice()
of classes extending the post type factory class were not displayed.color
field type by triggering a change event after setting a new value.path
custom field type due to the deprecation of the jQueryFileTree
library and switching to jstree
, which involves deprecation of some arguments and UI improvements.table
built-in field type.contact
built-in field type.selector
argument to the select2
custom field type that enables to show/hide elements on selection.a
tags.width
argument for the tip
field argument.color
field type are hidden by the color picker pallet in recent WordPress versions.tip
field argument made the document width wider than the initial width.save
of the submit
field type to false
.Generator
to Compiler
.email
argument of the submit
field type.