hook to add a comments menu option to each post type's admin menu

source : wp-hackers digest # 67,32,7.

add_action('admin_menu', 'hook_to_add_comment_admin_menu_option_for_each_post_type');
function hook_to_add_comment_admin_menu_option_for_each_post_type() {
$post_types = apply_filters('comment_admin_menu_post_types',get_post_types(array('public'=>true,'show_ui'=>true)));
foreach($post_types as $post_type) {
if ($post_type!='post') // Don't do for Posts, they already gota one! 
add_submenu_page("edit.php?post_type={$post_type}",__('Comments'),__('Comments'),'moderate_comments',"edit-comments.php?post_type={$post_type}" );
}
}

Note that it adds it's own filter comment_admin_menu_post_types so that someone using this can control via the hook in their own theme's function which post types get admin menus for Comments.

So if the two post_types you want comments for are "Movie" and "Actor" then this stored in the theme's functions.php file would cause only the menus for those post types to get a Comment option :

add_action('comment_admin_menu_post_types', 'my_comment_admin_menu_post_types');
function my_comment_admin_menu_post_types($post_types) {
return array('movie','actor');
}
 
 
Creative Commons License
This work by maniac.vardhan is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
 
 

0 comments :: hook to add a comments menu option to each post type's admin menu

Post a Comment