Skip to content

Instantly share code, notes, and snippets.

@mehrshaddarzi
Last active May 14, 2025 06:11
Show Gist options
  • Save mehrshaddarzi/2f91005fd310f36a1edaa128b59cc7fc to your computer and use it in GitHub Desktop.
Save mehrshaddarzi/2f91005fd310f36a1edaa128b59cc7fc to your computer and use it in GitHub Desktop.
disable User Agent in WordPress insert comment
<?php
// First Delete Bofore all agent from PHPMyAdmin
// UPDATE `wp_comments` SET `comment_agent` = '' AND `comment_author_IP` = '';
// Disable User Agent For WordPress Comment
// https://developer.wordpress.org/reference/functions/wp_new_comment/
add_filter( 'preprocess_comment', 'prepare_wp_insert_comment_data', 90, 1 );
function prepare_wp_insert_comment_data($commentdata) {
if(isset($commentdata['comment_agent']) and $commentdata['comment_agent'] != 'WooCommerce') {
$commentdata['comment_agent'] = '';
}
if(isset($commentdata['comment_author_IP'])) {
$commentdata['comment_author_IP'] = '';
}
return $commentdata;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment