Last active
May 14, 2025 06:11
-
-
Save mehrshaddarzi/2f91005fd310f36a1edaa128b59cc7fc to your computer and use it in GitHub Desktop.
disable User Agent in WordPress insert comment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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