我们正在创建一个插件,例如,它在所有帖子类型上显示一个元框。首先,我使用Starter Kit.
<?php
namespace PLUGIN_NAME;
class Foo
{
public function __construct() {
add_action( \'admin_init\', [ $this, \'wpd_add_meta_box\' ] );
}
function wpd_add_meta_box() {
$screens = get_post_types();
foreach ( $screens as $screen ) {
add_meta_box(
\'global-notice\',
__( \'Global Box \', \'global-box\' ),
\'global_box_meta_box_callback\',
$screen,
\'advanced\',
\'high\'
);
}
}
function global_box_meta_box_callback( $post ) {
echo "We\'re alive!"; // Never shows inside the metabox that is rendered.
}
}
在post页面上,我看到了metabox,但没有回调函数。将代码移动到functions.php
, 使用add_action( \'admin_init\',\'wpd_add_meta_box\')
, 一切正常。
如何从类中的插件呈现元数据库的内容?谢谢