Custom plugin settings link doesn’t append current class to menu item when visited? Why?

I noticed your apwb_settings_page() function is adding the “Postal Pricing Settings” submenu using add_options_page(), and the documentation stated that: (bold formatting added by me)

  • This function is a simple wrapper for a call to add_submenu_page(), passing the received arguments and specifying ‘options-general.php‘ as the $parent_slug argument. This means the new options page will be added as a sub menu to the Settings menu.

And that also means, in your apwb_settings_link() function, $admin_url (or your settings link) should actually link to or use options-general.php and not admin.php:

  • Incorrect: $admin_url = admin_url('admin.php?page=" . $slug);

  • Correct: $admin_url = admin_url("options-general.php?page=" . $slug);

  • Even better: Use menu_page_url(), e.g. $admin_url = menu_page_url( $slug, false );

The “Incorrect” above will actually load the correct “Postal Pricing Settings” admin page, but the “Postal Pricing Settings” submenu (under the “Settings” menu) will not be highlighted because the parent file is not options-general.php. So actually, you just needed to ensure your setting link uses the correct admin page URL. 🙂