我建议使用OOP构造,而不是运行到trac并抱怨缺少功能:
// File: base.class.php
abstract class wpse67649_admin_page_base
{
public function add_page()
{
add_submenu_page(
null // -> Set to null - will hide menu link
,\'Page Title\' // -> Page Title
,\'Menu Title\' // -> Title that would otherwise appear in the menu
,\'administrator\' // -> Capability level
,\'menu_handle\' // -> Still accessible via admin.php?page=menu_handle
,array( $this, \'render_page\' ) // -> To render the page
);
}
// Must get defined in extending class
abstract function render_page();
}
// File: ___sub_page.class.php
class wpse67649_render_sub_page extends wpse67649_admin_page_base
{
public function __construct()
{
add_action( \'admin_init\', array( $this, \'add_page\' ) );
}
public function render_page()
{
// You have access to every $this->class_var from your parent class
?>
<div class="wrapper>
<!-- do funky page rendering -->
</div>
<?php
}
}
这还不是最后一件事,但它应该会让你走上更好地组织事情的道路。