1. Home
  2. Docs
  3. WordPress Studio Framework
  4. Framework Locations
  5. Admin Options

Admin Options

There are many arguments that go into creating the base admin page options framework.

Arguments

NameTypeDefaultDescription of Argument
framework_titlestring Text to display in the framework header
menu_titlestring On-screen name text for the menu
menu_slugstring Slug name to refer to this menu by (should be unique)
menu_typestringmenuMenu Type (menu | submenu)
menu_parentstring 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_capabilitystringmanage_optionsThe capability required for this menu to be displayed to the user
menu_iconstring URL to the icon to be used for this menu
menu_positionnumber Position in the menu
menu_hiddenboolfalseFlag to display menu in the admin panel
show_bar_menubooltrueFlag to display menu in the admin bar
show_sub_menubooltrueFlag to display sub menus in the admin bar
show_network_menubooltrueFlag to display menu in the network bar
show_in_customizerboolfalseFlag to display options panel in customizer
show_searchbooltrueFlag to display search of the framework
show_reset_allbooltrueFlag to display reset button of the framework
show_reset_sectionbooltrueFlag to display reset section button of the framework
show_all_optionsbooltrueFlag to display show all options of the framework
sticky_headerbooltrueFlag to display sticky header feature of the framework
save_defaultsbooltrueFlag to save to default values of the framework
ajax_savebooltrueFlag to enable ajax save feature of the framework
admin_bar_menu_iconstring Icon to display before menu title
admin_bar_menu_prioritynumber80Position in the bar menu
footer_textstring Text to display in the footer of the framework
footer_afterstring Content to display after the framework
footer_creditstring Text to display in the footer of the framework
databasestringoptionDatabase save data type (option | theme_mod | transient |network)
transient_timenumber0The time until expiration in seconds from now, or 0 for never expires. If used database as transient.
contextual_helparray Contextual helps of the framework
contextual_help_sidebarstring Contextual sidebar help of the framework
enqueue_webfontbooltrueFlag to load web fonts of the framework
async_webfontboolfalseFlag to load google fonts with async method of the framework
output_cssbooltrueFlag to load output css of the framework
themestringdarkThe theme of the framework (dark | light)
classstring Extra CSS classes (space separated to assign to the framework
defaultsarray 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.

NameTypeDescription of Arguments
idstringA unique slug ID
parentstringSlug id for the parent section
titlestringTitle of the section
iconstringIcon of the section
fieldsarrayAssociative 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',
      ),
    )
  ));
}

 

 

Was this article helpful to you? Yes No

How can we help?