wp_lib_settings_tabs - roberts-sandbox/create-repo GitHub Wiki

###Description

This filter allows developers to modify WP-Librarian's settings page tabs, adding their own tabs or rearranging/removing existing tabs.

###Context

This filter is called on the plugin's settings page. For this filter to have been called the user must have permission to access the page, which implies the user is at least a Library Admin, or has been given the wp_lib_change_settings WordPress capability by some other means.

###Parameters

$settings_tabs
An array of the tabs that will display to the user. Each tab is stored as an array of this format:
$slug => array($settings_section_name, $tab_name)
These parameters are discussed below

$current_tab
The currently requested tab's $slug, or an empty string if no tab were specified (this will cause the default General Settings page to load). This parameter could be used to add a tab to the menu only if its URL is directly visited, creating a secret settings tab.

###Example

Suppose you want to add your own settings tab to the settings page. You'd need to first register a WordPress settings section:


add_action('admin_init', 'register_settings_tab');

function register_settings_tab() {
	add_settings_section('my_settings_section', 'My Settings Tab', function(){echo 'This is mine!';}, 'my_settings_section-options');
}

Then add your settings section to WP-Librarian's settings page. This adds the settings tab and instructs WP-Librarian to load your settings section when the tab is visited.


add_filter('wp_lib_settings_tabs', 'add_my_settings_tab', 10, 1);

function add_my_settings_tab($settings_tabs) {
	$settings_tabs['my_tab'] = array('my_settings_section', 'My Tab');
	
	return $settings_tabs;
}

These two snippets produce the following settings tab:

URL: edit.php?post_type=wp_lib_items&page=wp-lib-settings&tab=my_tab
From there you could register WordPress settings for your settings section with register_setting() then register fields for those settings with add_settings_field().

###Settings Tabs Format

$slug is the array key and a URL parameter used to access the tab e.g. &tab=slugs. The default settings tab used an empty string as its $slug.
$settings_section_name is the name parameter passed to add_settings_section(). WP-Librarian registers all its settings sections with the $page parameter of add_settings_section() as $settings_section_name . '-options.
$tab_name is the natural language name of the settings tab e.g. 'General'

⚠️ **GitHub.com Fallback** ⚠️