好吧,我在插件中有一个自定义帖子类型,插件结构为一个类 . 我也为插件设置了一些常量 .

我已经为自定义帖子类型创建了一个子菜单,但我的问题是,当我访问该页面时,它无法访问插件常量或类'$ this变量 . 救命!

这是我的代码:

add_action('admin_menu', array(&$this, 'add_psc_menu_page'));
function add_psc_menu_page(){
    add_submenu_page('edit.php?post_type=my-custom-post-type','Sub Menu','Sub Menu Title','manage_options','my-custom-post-type', array(&$this, 'render_psc_sub_page'));
}
function render_psc_sub_page(){
    include(PSC_PLUGIN_URL.'/util/custom-post-submenu-page.php');
}

在子菜单php文件中,尝试访问变量I KNOW设置如下:

$this->plugin_activated

爆炸了这个错误:

Fatal error: Using $this when not in object context

并尝试访问插件常量,如

PSC_PLUGIN_URL

给出错误:

Use of undefined constant PSC_PLUGIN_URL - assumed 'PSC_PLUGIN_URL'

当我可以创建没有问题的常规菜单时,我不确定如何将文件包含在自定义帖子的子菜单中会使事情脱离上下文 . 但是,我宁愿在自定义帖子类型下嵌套几个菜单项 .

你能指出我正确的方向,如何让这个子菜单页面访问$ this和插件的其余部分?任何帮助将不胜感激 . 谢谢 .