Cannot save metaboxes position in a WordPress plugin
I'm developing a WordPress plugin that presents a kind of dashboard, full of custom metaboxes. I was able to get the open/hide/close and drag handles working properly; however these screen customization are not saved: when I reload the page, everything goes to default config (actually, all metaboxes opened and sorted following the add_meta_box order in code).
I added this nonce code to my admin page, but nothing changes:
<form action="" method="">
开发者_运维技巧 <?php wp_nonce_field('dice-roller-metaboxes-settings'); ?>
<?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?>
<?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); ?>
<input type="hidden" name="action" value="save_dashboard_settings" />
</form>
Did I perhaps forgot something else?
you need to add some javascript to the bottom of the page that shows the metaboxes to handle the ajax save of the positions
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready( function($) {
// close postboxes that should be closed
$('.if-js-closed').removeClass('if-js-closed').addClass('closed');
// postboxes setup
postboxes.add_postbox_toggles('<?php echo $hook; ?>');
});
//]]>
</script>
be sure to change $hook in the add_postbox_toggles line to the correct value for the page you're on
精彩评论