Hooks
Docs Hooks Editor filters · JavaScript
modalKit.toolsRows
filter
Free
JavaScript
Add rows to the Tools tab on Modal Kit → Settings, between Setup wizard and Uninstall.
Runs each time the Tools tab of Modal Kit → Settings renders, in Free’s modal-kit-settings script. Each component in the returned array is rendered in the tab’s form table, after Setup wizard and before Uninstall.
Neither Free nor Modal Kit Pro adds rows here; it’s for other plugins.
Parameters
Parameter
Description
rows
Array
Components, empty by default.
Returns
Array Components. Each renders one table row and receives { notify }: notify( status, message ) shows a notice above the tab.
Example
Clear a page cache from Tools
After changing modals on a cached site. /my-plugin/v1/purge stands for a REST route of your own that checks the user’s capability.
import { __ } from '@wordpress/i18n';
import apiFetch from '@wordpress/api-fetch';
import { addFilter } from '@wordpress/hooks';
import { Button } from '@wordpress/components';
import { useState } from '@wordpress/element';
function PurgeRow( { notify } ) {
const [ busy, setBusy ] = useState( false );
const purge = async () => {
setBusy( true );
try {
await apiFetch( { path: '/my-plugin/v1/purge', method: 'POST' } );
notify( 'success', __( 'Page cache cleared.', 'my-plugin' ) );
} catch ( error ) {
notify( 'error', error.message );
}
setBusy( false );
};
return (
<tr>
<th scope="row">{ __( 'Page cache', 'my-plugin' ) }</th>
<td>
<Button
variant="secondary"
onClick={ purge }
isBusy={ busy }
disabled={ busy }
__next40pxDefaultSize
>
{ __( 'Clear the page cache', 'my-plugin' ) }
</Button>
<p className="description">
{ __( 'Visitors get the latest modals.', 'my-plugin' ) }
</p>
</td>
</tr>
);
}
addFilter( 'modalKit.toolsRows', 'my-plugin/purge', ( rows ) => [
...rows,
PurgeRow,
] );
Good to know
The rows sit inside a <tbody>, so return a <tr> with a <th scope="row"> and a <td>, not a panel or a <div>.
The Tools tab has a Save Changes button: a row that edits registered site settings (useEntityProp on root/site) is saved with it.
Load the script as for modalKit.settingsTabs: on admin_enqueue_scripts for mk_modal_page_modal-kit-settings, depending on modal-kit-settings.
Applied in modal-kit/src/admin/settings/tools.js.
Related