Quantcast
Channel: WordPress Cheat Sheets » admin
Viewing all articles
Browse latest Browse all 39

Cleaning up Commentluv Comments

$
0
0

If you ever used the commentluv plugin then you probably have a lot of WordPress comments with lots of links in it.

Manually editing all the comments and removing those links can be very tiresome. In this tutorial I will show you how you can easily clean up all the links from your comments using some PHP code.

CommentLuv Comment Cleanup Code

Step 1: Add the following block of code to your theme’s functions.php file

if(is_admin() && isset($_GET['run_comment_mod']))
{
//Do this from admin side only with a special query parameter
global $wpdb;
$comments_table = "wp_comments";
$resultset = $wpdb->get_results("SELECT *
FROM `wp_comments`
WHERE `comment_content` LIKE '%.-=%'
LIMIT 0 , 100", OBJECT);

foreach($resultset as $data)
{
echo "<br />------------ Comment start ----------- <br />";
//var_dump($data); //If you wanted to take a look at the data.
echo "<br />Comment Content Before: ".$data->comment_content;
$comment_exploded = explode('.-=',$data->comment_content);
echo "<br />Comment Content After: ".$comment_exploded[0];

//Now lets update the comment content
$commentarr = array();
$commentarr['comment_ID'] = $data->comment_ID;
$commentarr['comment_content'] = $comment_exploded[0];
wp_update_comment( $commentarr );
echo "<br />------------ Comment end ----------- <br />";
}
echo "All Done!";
exit;
}

Step 2: Now enter the following URL in your browsers address bar to trigger the above code which will clean up the commentluv comments (100 at a time). Keep executing it until all the comments are cleaned up.

Step 3: Once you are done, simply remove the code from your functions.php file.


Viewing all articles
Browse latest Browse all 39

Trending Articles