-
Notifications
You must be signed in to change notification settings - Fork 64
/
disable-all-comments.code-snippets.json
1 lines (1 loc) · 1.59 KB
/
disable-all-comments.code-snippets.json
1
{"generator":"Code Snippets v2.13.3","date_created":"2019-04-03 20:24","snippets":[{"name":"Disable All Comments","desc":"<a href=\"https:\/\/gist.github.com\/mattclements\/eab5ef656b2f946c4bfb\">https:\/\/gist.github.com\/mattclements\/eab5ef656b2f946c4bfb<\/a>","tags":["disable","comments","remove","frontend","backend","wp-admin"],"scope":"global","code":"add_action('admin_init', function () {\n \/\/ Redirect any user trying to access comments page\n global $pagenow;\n \n if ($pagenow === 'edit-comments.php') {\n wp_redirect(admin_url());\n exit;\n }\n\n \/\/ Remove comments metabox from dashboard\n remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');\n\n \/\/ Disable support for comments and trackbacks in post types\n foreach (get_post_types() as $post_type) {\n if (post_type_supports($post_type, 'comments')) {\n remove_post_type_support($post_type, 'comments');\n remove_post_type_support($post_type, 'trackbacks');\n }\n }\n});\n\n\/\/ Close comments on the front-end\nadd_filter('comments_open', '__return_false', 20, 2);\nadd_filter('pings_open', '__return_false', 20, 2);\n\n\/\/ Hide existing comments\nadd_filter('comments_array', '__return_empty_array', 10, 2);\n\n\/\/ Remove comments page in menu\nadd_action('admin_menu', function () {\n remove_menu_page('edit-comments.php');\n});\n\n\/\/ Remove comments links from admin bar\nadd_action('init', function () {\n if (is_admin_bar_showing()) {\n remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);\n }\n});","priority":"10"}]}