-
Notifications
You must be signed in to change notification settings - Fork 5
options
simmontali edited this page Sep 10, 2019
·
3 revisions
Generating settings pages is simple. Let’s create a new config file, naming it “options-example.json”. Like everywhere, we have three main fields available:
-
"name"
defines the internal name for this config file. -
"kind"
defines the type of configuration: we’re gonna set it to"options"
to create a setting page. -
"spec"
defines our settings page specific configuration.
{
"name": "menuwithoptions",
"spec": {},
"kind": "options"
}
If you want to leave this configuration disabled for now, you can add "enabled": false
to these fields.
The available specs are:
-
"title"
(Required): This defines the settings page title. -
"menu-slug"
(Required): This defines the settings page menu slug. In case of a new menu parent, this one will be ignored and"parent"
will be used instead. -
"capability"
(Optional): This defines the user’s needed privileges to see the settings page. By default, it is set to"manage_options
, so administrator only can see it. Check WordPress Codex for more information. -
"parent"
(Optional): This defines the menu parent containing this settings page. By default, the settings page is put under the “Settings” menu. If the declared parent is non-existent, Aeria will create it using:-
"parent_title"
: The parent menu’s title. -
"parent_icon"
: The parent menu’s icon. You can use dashicons, svgs or CSS. Check WordPress Codex for more informations.
-
Note that if a parent contains more than one menu page, the first item displayed will be a duplicate of the parent.
-
"fields"
:(Required): This is an array containing the settings page’s fields. Check Aeria’s wiki page about fields for more informations.
Our final settings page config looks like this:
{
"name": "menuwithoptions",
"spec": {
"title": "General options",
"parent": "aeria_options",
"menu_slug": "general_options",
"capability": "manage_options",
"parent_title": "Aeria",
"fields": [
{
"type": "text",
"id": "admin-name",
"value": "value",
"label": "Administrator surname",
"description": "description",
"size": "half",
"placeholder": "placeholder",
"required": true
},
{
"type": "text",
"id": "admin-email",
"label": "Email administrato",
"description": "description",
"size": "half",
"placeholder": "placeholder",
"required": true,
"validators": "isEmail"
}
]
},
"kind": "options"
}