WordPress 后台自定义菜单

wordpress 添加一个自定义菜单到后台控制面版

add_menu_page()
参数一是页面标题(必填)
参数二是菜单标题(必填)
参数三是用户对应级别显示,参数四是文件路径,参数四是回调函数名

add_action( 'admin_menu', 'register_my_custom_menu_page' );
function register_my_custom_menu_page() {
    add_menu_page( 'Custom Menu Page Title', 'Custom Menu Page', 'manage_options', basename(__FILE__), 'my_custom_landing_function', 'dashicons-welcome-widgets-menus', 90 );
}

回调方法中处理页面内容:

function my_custom_landing_function() {
?>
<div class="wrap">
    <h2>Application</h2>
    <p>Landing page</p>
</div>
<?php
}

注册子菜单

add_submenu_page()
参数一是父级菜单文件名称
参数二是页面标题
参数三是菜单标题
参数四是用户对应级别显示
参数五是页面的slug
能数六是回调函数名

function application_admin_submenu() {
   //
    add_submenu_page( 'functions.php', '页面标题', '菜单标题', 'manage_options', 'page-slug', 'application_import_export_page');
    //note: 可以查找对应函数信息,添加子菜单到对应主菜单下
    //Dashboard: add_submenu_page( 'index.php', ... ); Also see add_dashboard_page()
    //Posts: add_submenu_page( 'edit.php', ... ); Also see Also see add_posts_page()
    //Media: add_submenu_page( 'upload.php', ... ); Also see add_media_page()
    //Links: add_submenu_page( 'link-manager.php', ... ); Also see add_links_page()
    //Pages: add_submenu_page( 'edit.php?post_type=page', ... ); Also see add_pages_page()
    //Comments: add_submenu_page( 'edit-comments.php', ... ); Also see add_comments_page()
    //Custom Post Types: add_submenu_page( 'edit.php?post_type=your_post_type', ... );
    //Appearance: add_submenu_page( 'themes.php', ... ); Also see add_theme_page()
    //Plugins: add_submenu_page( 'plugins.php', ... ); Also see add_plugins_page()
    //Users: add_submenu_page( 'users.php', ... ); Also see add_users_page()
    //Tools: add_submenu_page( 'tools.php', ... ); Also see add_management_page()
    //Settings: add_submenu_page( 'options-general.php', ... ); Also see add_options_page()
    //Settings in the Network Admin pages: add_submenu_page( 'settings.php, ... );
}

回调方法中处理页面内容:

function application_import_export_page() {?>

<div class="wrap">
    <h2>Application</h2>
    <p>页面内容</p>
</div>

<?php }

372 total views, 2 views today

Revisions

There are no revisions for this post.

No comments yet.

发表评论