timkaye
December 15, 2019, 5:21pm
1
I have a regular plugin working fine with the new Security menu API, but I’d much prefer if I could get it to work from an mu-plugin
.
The problem I’m having is getting the API to look for the $menu_slug
in the mu-plugins
folder. The documentation says that the $menu_slug
should be:
The slug name to refer to this menu by; must match an active plugin or mu-plugin slug.
So there must be a way to do this. So what is it, please?
3 Likes
timkaye
December 15, 2019, 8:32pm
2
Aha! After looking at the add_security_page
code in plugin.php
, I finally have it working. The trick is to include the .php
suffix at the end of the mu-plugin
, and which you omit when the file is part of a regular plugin.
9 Likes
Code snippet would nice for future reference here
3 Likes
timkaye
December 16, 2019, 3:25pm
4
OK! My mu-plugin
is in a file called whitelist-blacklist.php
, so this is the code I used:
function kts_whitelist_blacklist() {
if ( function_exists( '\add_security_page' ) ) {
$page_title = 'Whitelist Blacklist';
$menu_title = 'Whitelist Blacklist';
$menu_slug = 'whitelist-blacklist.php';
$function = 'kts_whitelist_blacklist_setup';
add_security_page( $page_title, $menu_title, $menu_slug, $function );
}
else {
// existing code
}
}
add_action( 'admin_menu', 'kts_whitelist_blacklist' );
7 Likes