Usunięcie komentarzy do wordpressa przez functions.php

https://dfactory.eu/turn-off-disable-comments/

WordPress has a builtin comments system that works pretty well. However in some cases, especially if you use WordPress as a CMS, not a blogging platform, you may find it dispensable. For some of us turning off comments in Discussion settings is enough, but what if you want to disable access to the comments menu in admin, remove comments from admin bar and post types columns or hide existing comments at the front-end of your site? It’s not that easy, but this piece of code might help.

1 // Disable support for comments and trackbacks in post types
2 function df_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', 'df_disable_comments_post_types_support');
12
13 // Close comments on the front-end
14 function df_disable_comments_status() {
15     return false;
16 }
17 add_filter('comments_open', 'df_disable_comments_status', 20, 2);
18 add_filter('pings_open', 'df_disable_comments_status', 20, 2);
19
20 // Hide existing comments
21 function df_disable_comments_hide_existing_comments($comments) {
22     $comments = array();
23     return $comments;
24 }
25 add_filter('comments_array', 'df_disable_comments_hide_existing_comments', 10, 2);
26
27 // Remove comments page in menu
28 function df_disable_comments_admin_menu() {
29     remove_menu_page('edit-comments.php');
30 }
31 add_action('admin_menu', 'df_disable_comments_admin_menu');
32
33 // Redirect any user trying to access comments page
34 function df_disable_comments_admin_menu_redirect() {
35     global $pagenow;
36     if ($pagenow === 'edit-comments.php') {
37         wp_redirect(admin_url()); exit;
38     }
39 }
40 add_action('admin_init', 'df_disable_comments_admin_menu_redirect');
41
42 // Remove comments metabox from dashboard
43 function df_disable_comments_dashboard() {
44     remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
45 }
46 add_action('admin_init', 'df_disable_comments_dashboard');
47
48 // Remove comments links from admin bar
49 function df_disable_comments_admin_bar() {
50     if (is_admin_bar_showing()) {
51         remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
52     }
53 }
54 add_action('init', 'df_disable_comments_admin_bar');

After adding this to your functions.php file in theme, comments in WordPress will be gone.

Reklamy

Skomentuj

Wprowadź swoje dane lub kliknij jedną z tych ikon, aby się zalogować:

Logo WordPress.com

Komentujesz korzystając z konta WordPress.com. Wyloguj / Zmień )

Zdjęcie z Twittera

Komentujesz korzystając z konta Twitter. Wyloguj / Zmień )

Zdjęcie na Facebooku

Komentujesz korzystając z konta Facebook. Wyloguj / Zmień )

Zdjęcie na Google+

Komentujesz korzystając z konta Google+. Wyloguj / Zmień )

Connecting to %s