wordpresssubscriptionwordpress-jetpack

WordPress - import email subscriptions from *.csv file


How do we import email addresses for Jetpack subscriptions into WP from CSV file?


Solution

  • Have found the answer here and joined it with another answer from here:

    Jetpack subscriptions are not hosted on your site, they're hosted on the WordPress.com servers. So you can't add directly to the database.

    However, if you take a look at the Jetpack plugin code, it outlines the XML-RPC calls used to interface with WordPress.com and add subscribers. So you could build your own importer ...

    <?php
    //1. the "file_name_here.csv" should get changed to your need
    //2. the script just needs to get placed on site like "example.com/subscribe.php"
    //3. just execute it in the browser using your link
    
    require_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
    
    $row = 1;
    if (($handle = fopen("file_name_here.csv", "r")) !== FALSE) {
      while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        echo "<p> $num fields in line $row: <br /></p>\n";
        $row++;
        for ($c=0; $c < $num; $c++) {
            $email = $data[$c];
            echo $email . "<br />\n";
            Jetpack_Subscriptions::subscribe( $email );
        }
      }
      fclose($handle);
    }