无法在 WordPress 插件中保存元框位置
我正在开发一个 WordPress 插件,它提供了一种仪表板,其中充满了自定义元框。我能够使打开/隐藏/关闭和拖动手柄正常工作;但是,这些屏幕自定义不会保存:当我重新加载页面时,所有内容都会转到默认配置(实际上,所有元框都按照代码中的 add_meta_box 顺序打开和排序)。
我将此随机数代码添加到我的管理页面,但没有任何变化:
<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>
我是否忘记了其他内容?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在页面底部添加一些 javascript,以显示元框来处理位置的 ajax 保存,
请务必将 add_postbox_toggles 行中的 $hook 更改为您所在页面的正确值
you need to add some javascript to the bottom of the page that shows the metaboxes to handle the ajax save of the positions
be sure to change $hook in the add_postbox_toggles line to the correct value for the page you're on