Guest User

Untitled

a guest
Apr 20th, 2019
102
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Totally disable comments functionality
  2. function lp_disable_comments_post_types_support() {
  3. $post_types = get_post_types();
  4. foreach ( $post_types as $post_type ) {
  5. if ( post_type_supports( $post_type, 'comments' ) ) {
  6. remove_post_type_support( $post_type, 'comments' );
  7. remove_post_type_support( $post_type, 'trackbacks' );
  8. }
  9. }
  10. }
  11. add_action( 'admin_init', 'lp_disable_comments_post_types_support' );
  12. // Close comments on the front-end
  13. function lp_disable_comments_status() {
  14. return false;
  15. }
  16. add_filter( 'comments_open', 'lp_disable_comments_status', 20, 2 );
  17. add_filter( 'pings_open', 'lp_disable_comments_status', 20, 2 );
  18. // Hide existing comments
  19. function lp_disable_comments_hide_existing_comments( $comments ) {
  20. $comments = array();
  21.  
  22. return $comments;
  23. }
  24. add_filter( 'comments_array', 'lp_disable_comments_hide_existing_comments', 10, 2 );
  25. // Remove comments page in menu
  26. function lp_disable_comments_admin_menu() {
  27. remove_menu_page( 'edit-comments.php' );
  28. }
  29. add_action( 'admin_menu', 'lp_disable_comments_admin_menu' );
  30. // Redirect any user trying to access comments page
  31. function lp_disable_comments_admin_menu_redirect() {
  32. global $pagenow;
  33. if ( $pagenow === 'edit-comments.php' ) {
  34. wp_redirect( admin_url() );
  35. exit;
  36. }
  37. }
  38. add_action( 'admin_init', 'lp_disable_comments_admin_menu_redirect' );
  39. // Remove comments metabox from dashboard
  40. function lp_disable_comments_dashboard() {
  41. remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
  42. }
  43. add_action( 'admin_init', 'lp_disable_comments_dashboard' );
  44. // Remove comments links from admin bar
  45. function lp_disable_comments_admin_bar() {
  46. if ( is_admin_bar_showing() ) {
  47. remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 );
  48. }
  49. }
  50. add_action( 'init', 'lp_disable_comments_admin_bar' );
RAW Paste Data