Coding with Newsletter

This is an unofficial document to use the internal PHP methods and functions and it is still under construction.

What's inside

Getting the Newsletter instance

Generally, all methods described below are available from the Newsletter main object instance. We reference this object as $newsletter in this article and it can get using:

$newsletter = Newsletter::instance();

If you use an IDE to develop (like PHPStorm, Netbeans, …) you’ll have the code completion feature which helps a lot.

Get a subscriber

For historical reasons, subscribers are called users inside Newsletter. That could lead to some confusion with WordPress users, but they’re different and unrelated.

$subscriber = $newsletter->get_user(...);

The get_user(...) the method accepts an ID or an email. Both are unique to each subscriber. The method returns a standard PHP object, but the method signature declares it as TNP_User. That is only to have the code completion working correctly!

Save a subscriber

Once you retrieved a subscriber you can change its fields (for example you can set a list to on or off). Then you need to save it.

$subscriber = $newsletter->get_user(...);
$subscriber->list_2 = 1; // Set the list