我开始学习wordpress插件开发并尝试在我的插件中添加额外的子菜单,按照post_type上的文档,我试图在我的插件菜单底部添加一个设置子菜单,这是我的代码。
add_action( 'init', 'br_post_type');
function br_post_type() {
$labels = array(
'name' => _x( 'Book Reviews', 'post type general name', 'book-reviews' ),
'singular_name' => _x( 'Book Review', 'post type singular name', 'book-reviews' ),
'menu_name' => _x( 'Book Reviews', 'admin menu', 'book-reviews' ),
'add_submenu_page' => _x( 'Settings', 'admin menu', 'book-reviews' ),
'name_admin_bar' => _x( 'Book Review', 'add new on admin bar', 'book-reviews' ),
'add_new' => _x( 'Add New', 'book', 'book-reviews' ),
'add_new_item' => __( 'Add New Book', 'book-reviews' ),
'new_item' => __( 'New Book Review', 'book-reviews' ),
'edit_item' => __( 'Edit Book Review', 'book-reviews' ),
'view_item' => __( 'View Book Review', 'book-reviews' ),
'all_items' => __( 'All Books Review', 'book-reviews' ),
'search_items' => __( 'Search Books Review', 'book-reviews' ),
'parent_item_colon' => __( 'Parent Books Review:', 'book-reviews' ),
'not_found' => __( 'No review found.', 'book-reviews' ),
'not_found_in_trash' => __( 'No books review found in Trash.', 'book-reviews' )
);
$args = array(
'labels' => $labels,
'description' => __( 'Book review for our site.', 'book-reviews' ),
'public' => true,
'rewrite' => array( 'slug' => 'book_review' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'custom-fields' ),
'menu_icon' => 'dashicons-book'
);
register_post_type( 'book_review', $args );
}
我正在尝试添加这样的子菜单。
'add_submenu_page' => _x( 'Settings', 'admin menu', 'book-reviews' ),
但是没有任何显示,任何建议都会有所帮助,提前谢谢!
编辑以包含答案:
add_action('admin_menu', 'wpdocs_register_my_custom_submenu_page' );
function wpdocs_register_my_custom_submenu_page() {
add_submenu_page(
'edit.php?post_type=book_review',
'My Custom Submenu Page',
'My Custom Submenu Page',
'manage_options',
'my-custom-submenu-page',
'wpdocs_my_custom_submenu_page_callback' );
}
function wpdocs_my_custom_submenu_page_callback() {
echo '<div class="wrap"><div id="icon-tools" class="icon32"></div>';
echo '<h2>My Custom Submenu Page</h2>';
echo '</div>';
}