Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/*
Plugin Name: WP Comments by Post Type
Description: Enables PHP Developers to filter the comment admin at edit-comments.php by post type using a $_GET parameter. Use the "comment_admin_menu_post_types" hook to filter the array of post_type names to limit the admin menus that get a "Comments" option.
Version: 0.1
Author: Mike Schinkel
Author URI: http://mikeschinkel.com/custom-wordpress/plugins
*/
add_action('query', 'hook_to_filter_comment_admin_by_post_type');
function hook_to_filter_comment_admin_by_post_type($sql) {
global $pagenow;
if ($pagenow=='edit-comments.php' &&
!empty($_GET['post_type']) &&
post_type_exists($_GET['post_type']) &&
preg_match('#^SELECT \* FROM wp_comments c#',$sql)) {
$sql = str_replace(' WHERE '," WHERE p.post_type='{$_GET['post_type']}' AND ",$sql);
}
return $sql;
}
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}" );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment