Eliminar todos los comentarios pendientes:
wp comment delete $(wp comment list --status=all --format=ids) --force
// 1. Desactivar el soporte de comentarios en todos los post types.
function fla_disable_comments_from_post_types()
{
foreach (get_post_types() as $post_type) {
if (post_type_supports($post_type, 'comments')) {
remove_post_type_support($post_type, 'comments');
remove_post_type_support($post_type, 'trackbacks');
}
}
}
add_action('admin_init', 'fla_disable_comments_from_post_types');
// 2. Remover el menú de comentarios en el dashboard.
function fla_remove_comments_menu()
{
remove_menu_page('edit-comments.php');
}
add_action('admin_menu', 'fla_remove_comments_menu');
// 3. Deshabilitar la apertura de comentarios en el front-end.
function fla_disable_comments_status($open, $post_id)
{
return false;
}
add_filter('comments_open', 'fla_disable_comments_status', 20, 2);
add_filter('pings_open', 'fla_disable_comments_status', 20, 2);
// 4. Redirigir cualquier intento de acceder a wp-comments-post.php a una página 404.
function fla_redirect_wp_comments_post()
{
if (isset($_SERVER['SCRIPT_FILENAME']) && basename($_SERVER['SCRIPT_FILENAME']) === 'wp-comments-post.php') {
status_header(404);
nocache_headers();
// Si tu tema tiene una plantilla 404, se incluye. Si no, se muestra un mensaje simple.
if ($template = get_query_template('404')) {
include($template);
} else {
echo '404 Not Found';
}
exit;
}
}
add_action('init', 'fla_redirect_wp_comments_post');
// 5. Marcar automáticamente como spam cualquier comentario que se intente enviar.
function fla_auto_mark_comment_as_spam($approved, $commentdata)
{
// Siempre marca como "spam" cualquier comentario recibido.
return 'spam';
}
add_filter('pre_comment_approved', 'fla_auto_mark_comment_as_spam', 99, 2);