如果我很了解您想要在元框中显示小部件的添加和删除界面。
一种简单的、有点脏的方法是使用iframe:
function metaboxed_widgets_admin() {
if ( ! current_user_can( \'edit_theme_options\' ) ) return;
add_meta_box(\'metaboxed_widgets\', __(\'Widgets\'), \'metaboxed_widgets_admin_cb\', \'page\');
}
add_action( \'add_meta_boxes\', \'metaboxed_widgets_admin\' );
function metaboxed_widgets_admin_cb() {
if ( ! current_user_can( \'edit_theme_options\' ) ) return;
$format = \'<div style="margin:0px;padding:0px;">\';
$format .= \'<iframe src="%s" frameborder="0" %s></iframe></div>\';
// add a query arg to recognize when inside iframe, used to hide menu and admin bar
$url = add_query_arg(
array( \'iframe\'=> wp_create_nonce(\'widgets\') ), admin_url( \'widgets.php\' )
);
printf( $format, $url, \'style="height:1200px;width:100%;" height="100%" width="100%"\' );
}
function metaboxed_widgets_hide_stuff() {
if ( ! is_admin() || get_current_screen()->id !== \'widgets\' ) return;
$iframe = filter_input( INPUT_GET, \'iframe\', FILTER_SANITIZE_STRING );
if ( wp_verify_nonce( $iframe, \'widgets\' ) ) {
echo \'<style>\'
. \'#wpadminbar, #adminmenuback, #adminmenuwrap, #wpfooter, \'
. \'#screen-meta-links, .wrap > h2 { display:none!important; }\'
. \'#wpcontent { margin-left:25px!important; }\'
. \'.wrap{ margin-top:0!important; }</style>\';
}
}
add_action( \'admin_head-widgets.php\', \'metaboxed_widgets_hide_stuff\' );
请注意,只有能够看到小部件的用户才能查看小部件元盒,例如,除非您为编辑器提供
\'edit_theme_options\'
能力。