元框出现问题的原因是上下文不匹配。
当你打电话的时候add_meta_box
您可以指定$context
论点(第五个)作为一方。然而当你打电话的时候do_meta_boxes
您可以在上下文中执行此操作(第二个参数)normal
. 你需要改变其中一个,但它们应该匹配。
要使元盒看起来正确,还需要确保将它们放在类所在的容器中metabox-holder
.
您的代码将变成:
<?php
function wp_email_capture_show_lists()
{
$lists = wpecp_get_all_lists();
echo \'<div class="wrap metabox-holder">\';
do_meta_boxes(\'wpemailcaptureoptions\', \'side\' , NULL);
// snip snip
echo \'</div>\'; // close the wrap
}
这个问题让我好奇,所以我
wrote an example 如何在自定义页面上使用元框+设置API。可能会帮助您:
<?php
WPSE57092::init();
class WPSE57092
{
/**
* The hook to add an action to add our meta boxes.
*
*/
const ADD_HOOK = \'wpse57092_add_boxes\';
/**
* The page key for our meta boxes. You could use this as the "group" for
* the settings API as well or something similar.
*
*/
const PAGE = \'do_wpse57092_boxes\';
/**
* The setting key.
*
*/
const SETTING = \'wpse57092_opts\';
public static function init()
{
add_action(
\'admin_menu\',
array(__CLASS__, \'page\')
);
add_action(
self::ADD_HOOK,
array(__CLASS__, \'meta_box\')
);
add_action(
\'admin_init\',
array(__CLASS__, \'settings\')
);
}
public static function settings()
{
register_setting(
self::PAGE,
self::SETTING,
array(__CLASS__, \'validate\')
);
add_settings_section(
\'default\',
__(\'A Settings Section\', \'wpse57092\'),
\'__return_false\',
self::PAGE
);
add_settings_field(
\'wpse57092-text\',
__(\'Some Field\', \'wpse57092\'),
array(__CLASS__, \'field_cb\'),
self::PAGE,
\'default\',
array(\'label_for\' => self::SETTING)
);
}
public static function meta_box()
{
add_meta_box(
\'custom-meta-wpse57092\',
__(\'Just Another Meta Box\', \'wpse57092\'),
array(__CLASS__, \'box_cb\'),
self::PAGE,
\'main\',
\'high\'
);
}
public static function box_cb($setting)
{
// do_settings_fields doesn\'t do form tables for you.
echo \'<table class="form-table">\';
do_settings_fields(self::PAGE, \'default\');
echo \'</table>\';
}
public static function field_cb($args)
{
printf(
\'<input type="text" id="%1$s" name="%1$s" class="widefat" value="%2$s" />\',
esc_attr($args[\'label_for\']),
esc_attr(get_option($args[\'label_for\']))
);
echo \'<p class="description">\';
_e(\'Just some help text here\', \'wpse57092\');
echo \'</p>\';
}
public static function page()
{
$p = add_options_page(
__(\'WPSE 57092 Options\', \'wpse57092\'),
__(\'WPSE 57092\', \'wpse57092\'),
\'manage_options\',
\'wpse57092-options\',
array(__CLASS__, \'page_cb\')
);
}
public static function page_cb()
{
do_action(self::ADD_HOOK);
?>
<div class="wrap metabox-holder">
<?php screen_icon(); ?>
<h2><?php _e(\'WPSE 57092 Options\', \'wpse57092\'); ?></h2>
<p> </p>
<form action="<?php echo admin_url(\'options.php\'); ?>" method="post">
<?php
settings_fields(self::PAGE);
do_meta_boxes(self::PAGE, \'main\', self::SETTING);
?>
</form>
</div>
<?php
}
public static function validate($dirty)
{
return esc_url_raw($dirty);
}
}