Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. <?php
  2. // Add to existing function.php file
  3.  
  4. // Disable support for comments and trackbacks in post types
  5. function df_disable_comments_post_types_support() {
  6. $post_types = get_post_types();
  7. foreach ($post_types as $post_type) {
  8. if(post_type_supports($post_type, 'comments')) {
  9. remove_post_type_support($post_type, 'comments');
  10. remove_post_type_support($post_type, 'trackbacks');
  11. }
  12. }
  13. }
  14.  
  15. add_action('admin_init', 'df_disable_comments_post_types_support');
  16.  
  17. // Close comments on the front-end
  18. function df_disable_comments_status() {
  19. return false;
  20. }
  21.  
  22. add_filter('comments_open', 'df_disable_comments_status', 20, 2);
  23. add_filter('pings_open', 'df_disable_comments_status', 20, 2);
  24.  
  25. // Hide existing comments
  26. function df_disable_comments_hide_existing_comments($comments) {
  27. $comments = array();
  28. return $comments;
  29. }
  30.  
  31. add_filter('comments_array', 'df_disable_comments_hide_existing_comments', 10, 2);
  32.  
  33. // Remove comments page in menu
  34. function df_disable_comments_admin_menu() {
  35. remove_menu_page('edit-comments.php');
  36. }
  37.  
  38. add_action('admin_menu', 'df_disable_comments_admin_menu');
  39.  
  40. // Redirect any user trying to access comments page
  41. function df_disable_comments_admin_menu_redirect() {
  42. global $pagenow;
  43. if ($pagenow === 'edit-comments.php') {
  44. wp_redirect(admin_url()); exit;
  45. }
  46. }
  47.  
  48. add_action('admin_init', 'df_disable_comments_admin_menu_redirect');
  49.  
  50. // Remove comments metabox from dashboard
  51. function df_disable_comments_dashboard() {
  52. remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
  53. }
  54.  
  55. add_action('admin_init', 'df_disable_comments_dashboard');
  56.  
  57. // Remove comments links from admin bar
  58. function df_disable_comments_admin_bar() {
  59. if (is_admin_bar_showing()) {
  60. remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
  61. }
  62. }
  63.  
  64. add_action('init', 'df_disable_comments_admin_bar');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement