Arguments - rogerlos/cmb2-metatabs-options GitHub Wiki
CMO can accept the following arguments within the $args
array when being called:
new Cmb2_Metatabs_Options( $args );
Please check the arguments carefully if your options page is misbehaving. Below are the argument keys, their data type and default value, with notes on their use.
key
$args['key'] = (string) 'my_option'
Required. WordPress settings key. (Also used when you want to retrieve the values using get_option( 'my_option' )
.)
title
$args['title'] = (string) 'My Options Page'
Required. Friendly title of the options page.
topmenu
$args['topmenu'] = (string) ''
Optional. This key determines whether your options page will be added via a new top-level menu, as a sub-page of an existing admin page, or even hidden from the menu system:
Empty (''
) will add your options page as a new top-level menu.
Existing WP admin page (for example, 'general-options.php'
) will add your options page to that top-level menu (in this case, "Settings"). See https://codex.wordpress.org/Plugin_API/Admin_Screen_Reference for a list of possible locations to add your page. Note that this should be "edit.php" if you're adding an options page to a custom post type, see "postslug" below.
null (null
) will add your options page, but not make it visible in the menu system. You will need to link to it directly from elsewhere in admin.
Version 1.0.2: This can now also be set from within the menuargs
option, see below.
postslug
$args['postslug'] = (string) ''
Optional. This allows you to specify the slug of a custom post type, which will add an options page to its menu (or specify 'page', to add to the WordPress "page" menu). As far as I know, 'topmenu'
must be "edit.php" for this option to work successfully.
menuargs
$args['menuargs'] = array()
Optional. As of version 1.0.2, this is an associative array which can contain the following keys, all named per the WP docs for add_menu_page()
or add_submenu_page()
. Their formats must match the WP documentation for the parameter, but CMO does not actually check to see if they're properly formatted, for the most part.
$args['menuargs']['parent_slug'] = (string) $args['topmenu']
This is the same as setting topmenu
above. Either one will trigger adding a submenu page; leave both blank for new top menu. This value will always take priority over topmenu
(which is now deprecated).
$args['menuargs']['page_title'] = (string) $args['title']
This can be set, but currently CMO will not utilize it as anything other than a parameter when calling WP's add_menu_page()
or add_submenu_page()
. $args['title']
must still be set.
$args['menuargs']['menu_title'] = (string) $args['title']
By default, the menu title will be set to the page title.
$args['menuargs']['capability'] = (string) 'manage_options'
The WordPress capability required to see the menu.
$args['menuargs']['menu_slug'] = (string) $args['key']
The WordPress identifier for your menu. Defaults to the options key. Note that if you make this the same as your parent page's slug, the default WordPress action is to make the submenu page point at the same page as the parent, but use the submenupage 's menu_title
in the menu. This is how WP has "Posts" and its first child "All Posts" point at the same page.
$args['menuargs']['icon_url'] = (string) ''
For a top-level menu, allows setting the icon.
$args['menuargs']['position'] = (int) null
Use to adjust your menu's position in the admin bar.
$args['menuargs']['network'] = (bool) false
If you have a multisite installation, setting this to true will add your menu page to the network menu. (Added 1.1.0)
$args['menuargs']['view_capability'] = (bool|string) ''
CMO will check for this capability before displaying the page in admin. Options are:
''
(empty string, default): CMO uses the['menuargs']['capability']
argumentFALSE
: CMO will not check user capabilities before displaying page'your_string'
(WordPress capability): CMO will check this capability before displaying page
(Added 1.2)
jsuri
$args['jsuri'] = (string) plugin_dir_url( __FILE__ ) . 'cmb2multiopts.js'
Optional. You only need to configure this if you're using tabs and you've moved the JS file in relation to the php class file. The string should be suitable for using within admin_enqueue_scripts()
.
boxes
$args['boxes'] = array() \\ Array of CMB2 box objects and/or CMB2 box IDs
Optional. But recommended. See metaboxes in wiki. (CMB2 box IDs added 1.1.0)
tabs
$args['tabs'] = array() \\ Array of tab config arrays
Optional. But recommended if you're using tabs. See tabs page in wiki.
cols
$args['cols'] = (int) 1
Optional. Should be either 1 or 2, indicating whether you want a sidebar layout or not on your options page. Non-numbers, or numbers other than "1" or "2" will be ignored.
savetxt
$args['savetxt'] = (string) 'Save'
Optional. If you set this argument to an empty string, the save button below the form will be removed, and your options can only be saved if you add a save button back with the custom field type options_save_button
within one of your metaboxes (see the wiki page). If you pass a string to this argument, the save button below the form will display that string instead of the default "Save".
regkey
$args['regkey'] = (bool) true
Optional. If set to false, CMO will NOT register the option key you pass to it. This of course assumes you have done so elsewhere in your program. (Added 1.1.0)
getboxes
$args['getboxes'] = (bool) true
Optional. If set to false, CMO will NOT call CMB2_Boxes::get_all()
if the boxes
array is empty. This allows a text-only options page to be created (via the before and after filters). (Added 1.1.0)
load
$args['load'] = array()
Optional. This is an array of arrays allowing WordPress load-
actions to be called by an options page. See separate page in this wiki to learn how to configure these. (Added 1.1.0)
class
$args['class'] = (string) ''
Optional. Add a class or classes (separated by spaces) to the WordPress admin page wrap div. Useful if using your own styles. (Added 1.1.1)
admincss
$args['admincss'] = (bool|string) TRUE
Optional. If you set this to false, the "clean up" CSS CMO adds by default will be removed. If this is a string, it will be assumed (without validating!) that this is CSS to be added to the page. (Added 1.1.1)
plugincss
$args['plugincss'] = (bool) TRUE
Optional. If set to false, the plugin CSS will not be added, even if you send custom CSS via ['menuargs']['admincss']
. (Added 1.2)