Support » Fixing WordPress » Remove comments completely from settings

  • For every website we create we never use comments so we just disable them in settings. But I noticed that queries for them are still generated on each page in backend, for example in all posts list there are 2 queries triggered each time

    SELECT comment_approved, COUNT( * ) AS total 
    FROM wp_comments 
    GROUP BY comment_approved
    
    SELECT comment_post_ID, COUNT(comment_ID) as num_comments
    FROM wp_comments
    WHERE comment_post_ID IN ( XXX )
    AND comment_approved = '0'
    GROUP BY comment_post_ID

    It would be nice to optimize that a bit.

    This removes the page Comment from admin menu but queries are still generated

    function df_disable_comments_admin_menu() {
    remove_menu_page(‘edit-comments.php’);
    }
    add_action(‘admin_menu’, ‘df_disable_comments_admin_menu’);

Viewing 2 replies - 1 through 2 (of 2 total)
  • Yes, since comments can be enabled or disabled for each post or page, there is nothing to indicate that they were always disabled. Themes have to show any comments that are there, so it has to be checked.
    How would you propose to disable them permanently? You can write a Trac ticket for it, if you want. https://core.trac.wordpress.org/

    Hello, @filoveg and @joyously!

    I have had the same issue as you described. I think this query had to go away when you disable to commenting feature in the settings. But actually, it is not.

    I have found the hook that is placed before executing this query here
    wordpress/wp-includes/comment.php

    So you can override the behavior and trick the WordPress. I have set 1 comment and got rid of this query execution.

    This is my workaround:

    		add_filter( 'wp_count_comments', function () {
    			return 1;
    		} );
    

    I hope it will be helpful for someone.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Remove comments completely from settings’ is closed to new replies.