abuyoyo / adminmenupage
WordPress管理菜单页面辅助类
0.39
2024-09-14 00:00 UTC
Requires
- abuyoyo/metabox: ~0.8
Suggests
- abuyoyo/plugincore: ~0.26
- cmb2/cmb2: ~2.9
README
WordPress简单管理菜单页面注册的辅助类。
要求
安装
使用Composer作为库安装。
// Require the Composer autoloader anywhere in your code. require __DIR__ . '/vendor/autoload.php';
WPHelper\AdminMenuPage使用PSR-4来自动加载。
或者
作为WordPress插件安装并激活。
基本用法
// Import AdminPage. use WPHelper\AdminPage; // Register the admin menu page. $args = [ 'title' => 'The Tile of My Page', // title - passed to add_menu_page 'menu_title' => 'Page Title', // menu_title - passed to add_menu_page (optional - will use title if none provided) 'capability' => 'manage_options', // capability - passed to add_menu_page (optional - will default to 'manage_options') 'slug' => 'my_page', // slug - passed to add_menu_page 'template' => 'tpl/my_admin_page.php', // template - include file to print the page. wrapped in callback and passed to add_menu_page 'parent' => 'parent_page_slug'; // optional - slug of parent page if creating submenu 'icon_url' => $icon_url; // optional - icon url passed to add_menu_page/add_submenu_page 'position' => 4; // optional - passed to add_menu_page 'scripts' => [ // optional - script parameters passed to enqueue_scripts. Will only enqueue scripts on admin page [ 'script_handle', 'js/my_script.js', ['jquery'], false, true ], [ 'another_script', 'js/my_other_script.js', ['jquery', 'script_handle'], false, true ] ]; ]; // Register the admin menu page. $admin_menu_page = new AdminPage( $args ); // That's it. We're done. // This function can be called from anywhere. No need to wrap in any hook.