Dashboard like meta boxes in my plugin – how to save their position and open/closed state?

When ordering or closing metaboxes, those actions require nonces, add the following to your code and see if that resolves the problem.

<?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?>
<?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); ?>

Additional:

You should add metaboxes to your page using add_meta_box and output them using do_meta_boxes passing in the hook for your plugin page as the first arg. This should at least ensure you have registered and output them in the same way WordPress does, and providing you’ve also output the appropriate nonces, should work.

If something still isn’t working, view source on your problem page(s) and verify the JS files are being output in the correct order(easier still, compare JS inclusions in your page with a core WordPress page that uses metaboxes, make sure your JS includes(enqueues) appear in the same order).

Leave a Comment