wpfts_admin_tabs (Filter)
The wpfts_admin_tabs
filter in WP Fast Total Search allows developers to manage the tabs displayed on the plugin’s settings page in the WordPress admin panel. This filter can be used to add custom tabs, remove existing ones, or change their order.
When to Use
This filter is useful if your addon adds functionality that requires its own settings. By creating a new tab, you can organize your addon’s settings separately from the main WPFTS settings.
Arguments
$tabs
(array): An associative array of tabs. The keys of the array are the tab slugs (used in the URL), and the values are arrays containing the tab title, icon, and optionally, a callback function to display the tab content.
Return Value
$tabs
(array): The modified array of tabs.
Example (Adding a Tab)
add_filter('wpfts_admin_tabs', 'add_my_addon_tab');
function add_my_addon_tab($tabs) {
$tabs['my-addon-settings'] = array(
__('My Addon Settings', 'my-addon'), // Tab title.
'fa fa-cog', // Icon (Font Awesome).
'my_addon_settings_page' // Callback function to display the content.
);
return $tabs;
}
function my_addon_settings_page() {
// Addon settings page HTML code.
echo '<h2>'.__('My Addon Settings', 'my-addon').'</h2>';
// ... settings form ...
}
Example (Removing a Tab)
add_filter('wpfts_admin_tabs', 'remove_analytics_tab');
function remove_analytics_tab($tabs) {
unset($tabs['wpfts-options-analytics']); // Remove the "Analytics" tab.
return $tabs;
}
Example (Changing Tab Order)
add_filter( 'wpfts_admin_tabs', 'reorder_wpfts_tabs' );
function reorder_wpfts_tabs( $tabs ) {
$tabs_new = array();
$tab_order = array(
'wpfts-options-support',
'wpfts-options',
'wpfts-options-indexing-engine',
'wpfts-options-search-relevance',
'wpfts-options-sandbox-area',
'wpfts-options-analytics',
);
foreach ($tab_order as $tab_key) {
if (isset($tabs[$tab_key])) {
$tabs_new[$tab_key] = $tabs[$tab_key];
}
}
return $tabs_new;
}
Important Notes
- Tab slugs must be unique.
- The callback function specified in the tab array must output the HTML code for the tab content.
- After adding/removing tabs, you need to clear your browser cache for the changes to take effect.
The wpfts_admin_tabs
filter gives developers full control over the tabs on the WP Fast Total Search settings page, allowing them to create a user-friendly interface for managing addon settings.