Software Developer

Subscribe Existing Commentators Into Comment Notifier Plugin

This is for you if you are using the WordPress Comment Notifier Plugin by Satollo. The purpose of this is to automatically subscribe your existing commentators (which are people who have already made comments to your blog). You want to add these people as subscribers to this Comment Notifier Plugin, or they get left out of the discussion.

This may be because you were using a different plugin before, and they have already subscribed to comments previously, but now you are using this plugin, and they are not automatically subscribed.

This script will grab each commentator’s name, email address, and the post ID that they commented on from the wp_comments table in the WordPress database. Then it will insert that data into the new wp_comment_notifier table which pertains to this plugin (Comment Notifier Plugin). It will also generate and insert the token which the Comment Notifier Plugin table requires.

Step by Step Instructions

1. Paste the following PHP script into a blank file.

<?php

$db = new PDO('mysql:host=YOUR_MYSQL_HOST_HERE;dbname=YOUR_DATABASE_NAME_HERE', 'YOUR_DATABASE_USERNAME_HERE', 'YOUR_DATABASE_PASSWORD_HERE', array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,));
 

// prep an array
$row = array();
$table1 = "SELECT `comment_post_ID`, `comment_author`, `comment_author_email` FROM `wp_comments` WHERE (`comment_author_email`<> '')";

$result = $db->query($table1);

$row = $result->fetchAll(); // this array holds my incoming data

$stmt = $db->prepare('INSERT IGNORE INTO `wp_comment_notifier` (`post_id`, `name`, `email`, `token`) VALUES (?,?,?,?)');
 
foreach ($row as $justone) {

    $token = md5(rand());
    $count = $stmt->execute(array($justone[0], $justone[1], $justone[2], $token));
}
 
$numAffected = count($row) + 1;
echo 'Inserted this many rows: '.$numAffected ;

?>

2. Edit the code above by making these 4 changes to line 3:

Change YOUR_MYSQL_HOST_HERE to your own MYSQL HOST.

Change YOUR_DATABASE_NAME_HERE to your own database name.

Change YOUR_DATABASE_USERNAME_HERE to your own database username.

Change YOUR_DATABASE_PASSWORD_HERE to your own database password.

3. Save the file as a .php file. You can name it whatever you like, but it needs to end with the .php extension.

4. Upload it to your server.

5. Run it once by navigating to that file in a web browser.

6. You should delete it from your server after this.

Now all your existing users who have commented should be listed as subscribers. Go to your WordPress dashboard, ‘Settings –> Comment Notifier‘, and scroll all the way to the bottom. You should see your “Long list of subscribers“.

By

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]