Title: PHP Code to add subscriber
Last modified: September 1, 2016

---

# PHP Code to add subscriber

 *  Resolved [theupdatecompany](https://wordpress.org/support/users/theupdatecompany/)
 * (@theupdatecompany)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/php-code-to-add-subscriber/)
 * We were using a function hooked into the save_post action to add a comment subscription.
   
   It subscribes an email address that is not the article author but stored in a
   custom field.
 * The function has recently stopped working after an upgrade
 * The relevant line is:
 * `new comment_mail\sub_inserter($sub_insert_data);`
 * What should we be using?
 * [https://wordpress.org/plugins/comment-mail/](https://wordpress.org/plugins/comment-mail/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [Raam Dev](https://wordpress.org/support/users/raamdev/)
 * (@raamdev)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/php-code-to-add-subscriber/#post-7606283)
 * [@theupdatecompany](https://wordpress.org/support/users/theupdatecompany/) The
   namespace changed in the latest version; it’s now `WebSharks\CommentMail`. So
   the following should work:
 * `new WebSharks\CommentMail\sub_inserter($sub_insert_data);`
 *  Thread Starter [theupdatecompany](https://wordpress.org/support/users/theupdatecompany/)
 * (@theupdatecompany)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/php-code-to-add-subscriber/#post-7606325)
 * Thanks – forgive my ignorance but do I need a use statement or something else
   for this to work in my theme’s functions.php? It still reports ‘class not found’
 *  [Raam Dev](https://wordpress.org/support/users/raamdev/)
 * (@raamdev)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/php-code-to-add-subscriber/#post-7606382)
 * [@theupdatecompany](https://wordpress.org/support/users/theupdatecompany/) Try
   something like this:
 *     ```
       <?php
       use WebSharks\CommentMail\SubInserter;
   
       $sub_insert_data = array(
         'post_id'        => 123,
         'status'         => 'subscribed',
         'deliver'        => 'asap',
         'fname'          => 'John',
         'email'          => 'john@example.com',
       );
       $SubInserter = new SubInserter($sub_insert_data); // Inserts new subscriber.
   
       if ($SubInserter->hasErrors()) {
           print_r($SubInserter->errors());
           //print_r($SubInserter->errorCodes());
           //print_r($SubInserter->errorsHtml());
       }
       ```
   
 * Also, I opened a feature request to add the `SubInserter()` method to the Comment
   Mail API so that this can be done more easily in a future version: [https://github.com/websharks/comment-mail/issues/290](https://github.com/websharks/comment-mail/issues/290)
 *  Thread Starter [theupdatecompany](https://wordpress.org/support/users/theupdatecompany/)
 * (@theupdatecompany)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/php-code-to-add-subscriber/#post-7606390)
 * Thanks – got it working with a slight change, we are using the Pro version so
   it’s
 * ‘use WebSharks\CommentMail\Pro\SubInserter;’
 *  [Raam Dev](https://wordpress.org/support/users/raamdev/)
 * (@raamdev)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/php-code-to-add-subscriber/#post-7606401)
 * [@theupdatecompany](https://wordpress.org/support/users/theupdatecompany/) Cool.
   🙂 Glad to hear you got it working.
 * For future reference, we’re not allowed to provide support for the Pro version
   here on the WordPress.org forums, but since you have a license you’re more than
   welcome to [open a support ticket](https://cometcache.com/support/) or post your
   questions on our [main community forum](https://forums.wpsharks.com/c/comet-cache).
   Thanks for going Pro! 🙂

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘PHP Code to add subscriber’ is closed to new replies.

 * ![](https://ps.w.org/comment-mail/assets/icon-256x256.png?rev=1210411)
 * [Comment Mail](https://wordpress.org/plugins/comment-mail/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/comment-mail/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/comment-mail/)
 * [Active Topics](https://wordpress.org/support/plugin/comment-mail/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/comment-mail/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/comment-mail/reviews/)

## Tags

 * [function](https://wordpress.org/support/topic-tag/function/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * 5 replies
 * 2 participants
 * Last reply from: [Raam Dev](https://wordpress.org/support/users/raamdev/)
 * Last activity: [9 years, 9 months ago](https://wordpress.org/support/topic/php-code-to-add-subscriber/#post-7606401)
 * Status: resolved