Update menu when save settings

I have a settings page for my plugin in which the user can toggle a custom post type on or off. When the plugin is initialized I then check this setting to see if the custom content type should be registered or not:

function initialize() {
if ($this->setting->get(‘enable_cpt’)) {

function registerPostType() {
$args = array(

register_post_type(‘my-custom-cpt’, $args);

This works as expected, but the problem is that when I’m saving the form the menu item for the custom post type is not visible until I reload the page. Obviously this is because the menu is already created.

I tried to use wp_redirect() after the setting is saved, but I’m not able to set any headers because the output has already started.

Can someone please explain how I can make the menu item for my custom post type update when saving the setting for my plugin?

Read more here:: Update menu when save settings

Leave a Reply

Your email address will not be published. Required fields are marked *