Skip to content

Instantly share code, notes, and snippets.

@damianwajer
Last active August 29, 2015 14:11
Show Gist options
  • Save damianwajer/d2446d014b2c331b3db2 to your computer and use it in GitHub Desktop.
Save damianwajer/d2446d014b2c331b3db2 to your computer and use it in GitHub Desktop.
[WordPress] Remove comments support
/* thanks to: http://www.catswhocode.com/blog/manage-wordpress-comments-using-sql */
/* Delete all spam comments */
DELETE from wp_comments WHERE comment_approved = 'spam';
/* Delete all comments between two dates */
DELETE FROM wp_comments
WHERE comment_date > '2013-11-15 01:10:04'
AND comment_date <= '2013-11-20 00:10:04';
/* Delete all pending comments */
DELETE FROM wp_comments WHERE comment_approved = '0';
/* Disable comments on all posts at once */
UPDATE wp_posts SET comment_status = 'closed', ping_status = 'closed' WHERE comment_status = 'open';
/* Disable comments on older posts */
UPDATE wp_posts SET comment_status = 'closed' WHERE post_date < '2014-01-01' AND post_status = 'publish';
/* Delete comments with a specific url */
DELETE from wp_comments WHERE comment_author_url LIKE "%nastyspamurl%";
/* Search and replace comment text */
UPDATE wp_comments SET `comment_content` = REPLACE (`comment_content`, 'OriginalText', 'ReplacedText');
/* Globally enable comments for registered users only */
UPDATE wp_posts SET comment_status = 'registered_only';
<?php
/**
* Remove comments and pings/trackbacks support
*/
function remove_comments_support() {
remove_post_type_support( 'post', 'comments' );
remove_post_type_support( 'post', 'trackbacks' );
remove_post_type_support( 'page', 'comments' );
remove_post_type_support( 'page', 'trackbacks' );
}
add_action( 'init', 'remove_comments_support', 100 );
/**
* Remove comments menu
*/
function remove_menus() {
remove_menu_page( 'edit-comments.php' );
}
add_action( 'admin_menu', 'remove_menus' );
/**
* Remove Emoji scripts and styles
*/
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment