There are many arguments that go into creating the base admin page options framework.
Arguments
Name | Type | Default | Description of Argument |
---|---|---|---|
framework_title | string | Text to display in the framework header | |
menu_title | string | On-screen name text for the menu | |
menu_slug | string | Slug name to refer to this menu by (should be unique) | |
menu_type | string | menu | Menu Type (menu | submenu) |
menu_parent | string | Slug name for the parent menu (or the file name of a standard WordPress admin page). for eg. themes.php plugins.php options-general.php tools.php Note: menu_type must be submenu | |
menu_capability | string | manage_options | The capability required for this menu to be displayed to the user |
menu_icon | string | URL to the icon to be used for this menu | |
menu_position | number | Position in the menu | |
menu_hidden | bool | false | Flag to display menu in the admin panel |
show_bar_menu | bool | true | Flag to display menu in the admin bar |
show_sub_menu | bool | true | Flag to display sub menus in the admin bar |
show_network_menu | bool | true | Flag to display menu in the network bar |
show_in_customizer | bool | false | Flag to display options panel in customizer |
show_search | bool | true | Flag to display search of the framework |
show_reset_all | bool | true | Flag to display reset button of the framework |
show_reset_section | bool | true | Flag to display reset section button of the framework |
show_all_options | bool | true | Flag to display show all options of the framework |
sticky_header | bool | true | Flag to display sticky header feature of the framework |
save_defaults | bool | true | Flag to save to default values of the framework |
ajax_save | bool | true | Flag to enable ajax save feature of the framework |
admin_bar_menu_icon | string | Icon to display before menu title | |
admin_bar_menu_priority | number | 80 | Position in the bar menu |
footer_text | string | Text to display in the footer of the framework | |
footer_after | string | Content to display after the framework | |
footer_credit | string | Text to display in the footer of the framework | |
database | string | option | Database save data type (option | theme_mod | transient |network) |
transient_time | number | 0 | The time until expiration in seconds from now, or 0 for never expires. If used database as transient. |
contextual_help | array | Contextual helps of the framework | |
contextual_help_sidebar | string | Contextual sidebar help of the framework | |
enqueue_webfont | bool | true | Flag to load web fonts of the framework |
async_webfont | bool | false | Flag to load google fonts with async method of the framework |
output_css | bool | true | Flag to load output css of the framework |
theme | string | dark | The theme of the framework (dark | light) |
class | string | Extra CSS classes (space separated to assign to the framework | |
defaults | array | Sets all default values from an external array. |
The Admin Options location also has some custom Section Arguments that are used in this specific setup.
Name | Type | Description of Arguments |
---|---|---|
id | string | A unique slug ID |
parent | string | Slug id for the parent section |
title | string | Title of the section |
icon | string | Icon of the section |
fields | array | Associative array containing fields for the field sets. |
Now that you’ve seen all the arguments that can be utilized in the Admin Options setup, let’s take a look at a few examples.
Simple Admin Options Framework
//Make sure the framework is loaded on the site
if ( class_exists( 'WPSF' ) ){
//Set unique ID
$prefix = 'admin_options';
//Create Options
WPSF::createOptions( $prefix, array(
'menu_title' => 'Admin Options',
'menu_slug' => 'admin-options',
) );
// Create a Section
WPSF::createSection( $prefix, array(
'title' => 'Tab Title One',
'fields' => array(
//text field
array(
'id' => 'example-text',
'type' => text',
'title' => 'Simple Text Field',
),
)
) );
}
Before we look at a few additional examples of creating an Admin Options setup of the WordPress Framework Studio code, let’s recap two ways you can extract the values out of the database for usage in your theme and/or code.
Admin Options with Tabs
if ( class_exists( 'WPSF' ) ){
$prefix = 'admin_options_tabs';
WPSF::createOptions( $prefix, array(
'menu_title' => 'Admin Options with Tabs',
'menu_slug' => 'admin-options-tabs',
));
WPSF::createSection( $prefix, array(
'id' => 'primary_tab',
'title' => 'Primary Tab',
));
WPSF::createSection( $prefix, array(
'parent' => 'primary_tab',
'title' => 'Sub Tab One',
'fields' => array(
array(
'id' => 'example-text',
'type' => 'text',
'title' => 'Simple Text Field',
),
)
));
WPSF::createSection( $prefix, array(
'parent' => 'primary_tab',
'title' => 'Sub Tab Two',
'fields' => array(
array(
'id' => 'example-textarea',
'type' => 'textarea',
'title' => 'Simple Textarea',
),
)
));
WPSF::createSection( $prefix, array(
'id' => 'secondary_tab',
'title' => 'Secondary Tab',
));
WPSF::createSection($prefix, array(
'parent' => 'secondary_tab',
'title' => 'Sub Tab One',
'fields' => array(
array(
'id' => 'example-switcher',
'type' => 'switcher',
'title' => 'Simple Switcher',
),
)
));
}
Admin Options with Submenus
if ( class_exists( 'WPSF' ) ){
$prefix = 'admin_options_submenus';
/*
* menu_parent argument examples.
*
* For Dashboard: 'index.php'
* For Posts: 'edit.php'
* For Media: 'upload.php'
* For Pages: 'edit.php?post_type=page'
* For Comments: 'edit-comments.php'
* For Custom Post Types: 'edit?post_type=post_type_slug'
* For Appearance: 'themes.php'
* For Plugins: 'plugins.php'
* For Users: 'users.php'
* For Tools: 'tools.php'
* For Settings: 'options-general.php'
*/
WPSF::createOptions( $prefix, array(
'menu_title' => 'Admin Options',
'menu_slug' => 'admin-options',
'menu_type' => 'submenu',
'menu_parent' => 'themes.php',
));
WPSF::createSection( $prefix, array(
'title' => 'Tab Title One',
'fields' => array(
array(
'id' => 'example-text',
'type' => 'text',
'title' => 'Simple Text',
),
)
));
WPSF::createSection( $prefix, array(
'title' => 'Tab Title Two',
'fields' => array(
array(
'id' => 'example-textarea',
'type' => 'textarea',
'title' => 'Simple Textarea',
),
)
));
}
And finally, here is an example with the kitchen sink added to the setup…
Full Admin Options Framework
if ( class_exists( 'WPSF' ) ){
$prefix = 'admin_options';
WPSF::createOptions( $prefix, array(
//framework title
'framework_title' => 'Bob Bobbertson Admin Options',
'framework_class' => '',
//menu settings
'menu_title' => '',
'menu_slug' => '',
'menu_type' => 'menu',
'menu_capability' => 'manage_options',
'menu_icon' => null,
'menu_position' => null,
'menu_hidden' => false,
'menu_parent' => '',
//menu extras
'show_bar_menu' => true,
'show_sub_menu' => true,
'show_network_menu' => true,
'show_in_customizer' => false,
'show_search' => true,
'show_reset_all' => true,
'show_reset_section' => true
'show_footer' => true,
'show_all_options' => true,
'sticky_header' => true,
'save_defaults' => true,
'ajax_save' => true,
//admin bar menu settings
'admin_bar_menu_icon' => '',
'admin_bar_menu_priority' => 80,
//footer
'footer_text' => '',
'footer_after' => '',
'footer_credit' => '',
//database model
'database' => '', //options, transient, theme_mod, network
'transient_time' => 0,
//contextual help
'contextual_help' => array(),
'contextual_help_sidebar' => '',
//typography options
'enqueue_webfont' => true,
'async_webfont' => false,
// others
'output_css' => true,
'theme' => 'dark',
'class' => '',
'defaults' => array(),
));
WPSF::createSection( $prefix, array(
'title' => 'Tab Title One',
'fields' => array(
array(
'id' => 'example-text',
'type' => 'text',
'title' => 'Simple Text',
),
)
));
}