Title: Custom Hooks
Last modified: August 30, 2016

---

# Custom Hooks

 *  Resolved [eupalinos](https://wordpress.org/support/users/eupalinos/)
 * (@eupalinos)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/custom-hooks-1/)
 * Hi, Eventualo.
    How’re you doing? I hope everything is fine.
 * At the moment, I’m sending out two attachments for every newsletter subscriber
   using the function snippet below, inside the mu-plugin folder.
 * I was wondering how I could tweak it to send out either two attachments in Italian
   or two attachments in English, depending on the selection the subscriber makes
   for the newsletter language (Italian / English.)
 * If you could help me yourself, or direct me to some site that has some information.
 * PS.: When the email field is empty, your plugin gives the message:
    “The e-email
   address is not correct”, but should be: “The e-mail address is not correct” e-
   mail, not e-email.
 * Thanks!
 * Marco.
 * ————————————– custom hooks function snippet
 * function custom_easymail_subscriber_activated ( $email ) {
    // uncomment next
   lines to send a welcome message to just-activated subscribers add_filter(‘wp_mail_content_type’,
   create_function(”, ‘return “text/html”; ‘)); $attachments = array(); $subscriber
   = alo_em_get_subscriber( $email ); $subject = “Welcome to the Newsletter!”; $
   body = file_get_contents(WP_CONTENT_DIR . ‘/uploads/email_text.php’); array_push(
   $attachments, WP_CONTENT_DIR . ‘/profile-pics/attachment1.epub’ ); array_push(
   $attachments, WP_CONTENT_DIR . ‘/profile-pics/attachment2.mobi’ ); wp_mail( $
   email, $subject, $body, false, $attachments); } ——————————————————
 * [https://wordpress.org/plugins/alo-easymail/](https://wordpress.org/plugins/alo-easymail/)

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

 *  Plugin Author [eventualo](https://wordpress.org/support/users/eventualo/)
 * (@eventualo)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/custom-hooks-1/#post-6486470)
 * You can get the 2-chars-language-code using `alo_em_get_language` function, then
   you can attach the right files depending on the language.
    A quick sample:
 *     ```
       $lang = alo_em_get_language();
   
       if ( $lang == 'en' ) {
           // The English attachs
           array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment1_EN.epub';
           // ...
       } else if ( $lang == 'it' ) {
           // The Italian attachs
           array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment1_IT.epub';
           // ...
       }
       ```
   
 *  Thread Starter [eupalinos](https://wordpress.org/support/users/eupalinos/)
 * (@eupalinos)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/custom-hooks-1/#post-6486472)
 * Hello, Eventualo.
 * Unfortunately, browser language is not an effective discriminant for me, since
   for instance US subscribers using an english language-based browser may want 
   to opt in to the Italian Newsletter. Or an Italian-based user may want to receive
   the English Newsletter.
 * Moreover, I got a lot of subscribers with an empty Language tab in the Alo Easy
   Mail Subscribers panel.
 * That’s why attachments based on subscription list-IDs would be more to the point
   IMHO, because subscribers would choose the list, hence what they’d like to be
   sent. Just think of a subscription policy based on book genres (romance, sci-
   fi, thriller, etc.) that gives away samples on subscription. In this case, language
   would be irrelevant.
 * Can’t it be done using list IDs?
 * Thank you for yor time.
 * Again, don’t forget to change the “e-email” to “e-mail” in the messages printed
   out by your plugin.
 * Marco.
 *  Thread Starter [eupalinos](https://wordpress.org/support/users/eupalinos/)
 * (@eupalinos)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/custom-hooks-1/#post-6486478)
 * Hello.
 * I tried this, but nothing is sent after the activation, ergo that’s not the right
   way to retrieve the $list_id parameter:
 *     ```
       $attachments = array();
   
       $subscriber = alo_em_get_subscriber( $email );
   
       if ( $list_id == 2 ) {
           // The English attachs
       	$subject = "Welcome to the Newsletter!";
       	$body = file_get_contents(WP_CONTENT_DIR . '/uploads/eng.php');
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment1_eng.epub' );
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment2_eng.mobi' );
           // ...
       } else if ( $list_id == 6 ) {
           // The Italian attachs
       	$subject = "Benvenuto alla Newsletter!";
       	$body = file_get_contents(WP_CONTENT_DIR . '/uploads/ita.php');
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment1_ita.epub' );
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment2_ita.mobi' );}
   
       wp_mail( $email, $subject, $body, false, $attachments);
   
       }
       ```
   
 *  Thread Starter [eupalinos](https://wordpress.org/support/users/eupalinos/)
 * (@eupalinos)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/custom-hooks-1/#post-6486479)
 * This isn’t working, either:
 *     ```
       $attachments = array();
       $subscriber = alo_em_get_subscriber( $email );
   
       $listnum = alo_em_get_subscriber( $list_id );
   
       if ( $listnum == 2 ) {
           // The English attachs
       	$subject = "Welcome to the Newsletter!";
       	$body = file_get_contents(WP_CONTENT_DIR . '/uploads/eng.php');
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment1_eng.epub' );
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment2_eng.mobi' );
           // ...
       } else if ( $listnum == 6 ) {
           // The Italian attachs
       	$subject = "Benvenuto alla Newsletter!";
       	$body = file_get_contents(WP_CONTENT_DIR . '/uploads/ita.php');
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment1_ita.epub' );
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment2_ita.mobi' );}
   
       wp_mail( $email, $subject, $body, false, $attachments);
   
       }
       ```
   
 *  Thread Starter [eupalinos](https://wordpress.org/support/users/eupalinos/)
 * (@eupalinos)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/custom-hooks-1/#post-6486481)
 * All right, scratch the last two incomplete posts.
 * I tried this as well, but it doesn’t work (it always sends the ELSE condition.)
 *     ```
       $attachments = array();
   
       	$subscriber = alo_em_get_subscriber( $email );	
   
       if(isset($_POST['alo_em_form_lists[]']) && $_POST['alo_em_form_lists[]']==='2') {
           // The English attachs
       	$subject = "Welcome to the Newsletter!";
       	$body = file_get_contents(WP_CONTENT_DIR . '/uploads/html_eng.php');
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment1_eng.epub' );
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics//attachment2_eng.mobi' );}
           // ...
   
       elseif(isset($_POST['alo_em_form_lists[]']) && $_POST['alo_em_form_lists[]']==='6') {
           // The Italian attachs
       	$subject = "Benvenuto alla Newsletter!";
       	$body = file_get_contents(WP_CONTENT_DIR . '/uploads/html_ita.php');
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment1_ita.epub' );
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics//attachment2_ita.mobi' );}
           // ...
   
       else {
           // The English attachs
       	$subject = "Welcome to the Newsletter!";
       	$body = file_get_contents(WP_CONTENT_DIR . '/uploads/html_eng.php');
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment1_eng.epub' );
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics//attachment2_eng.mobi' );}
           // ...
   
       wp_mail( $email, $subject, $body, false, $attachments);
       ```
   
 * Thanks for your help.
 * Marco.
 *  Plugin Author [eventualo](https://wordpress.org/support/users/eventualo/)
 * (@eventualo)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/custom-hooks-1/#post-6486485)
 * Ok, I understand.
    About the subscriber mailing list you can use `alo_em_get_user_mailinglists`
   that returns an array of list IDs, e.g.:
 *     ```
       $attachments = array();
   
       $subscriber = alo_em_get_subscriber( $email );
       $lists = alo_em_get_user_mailinglists( $subscriber->ID );
       foreach ( $lists as $list ) {
           if ( $list == 1 ) { // the list ID
               array_push($attachments, WP_CONTENT_DIR . '/profile-pics//attachment_list_1.mobi' );
           }
           /* else if list == 2 .... etc */
       }
       ```
   
 * About my first snippet, it’s wrong about subscriber language. You can get it 
   with `alo_em_get_subscriber`, e.g.:
 *     ```
       $subscriber = alo_em_get_subscriber( $email );
       if ( $subscriber->lang == 'it' ) {
           // ...
       } // else ...
       ```
   
 *  Thread Starter [eupalinos](https://wordpress.org/support/users/eupalinos/)
 * (@eupalinos)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/custom-hooks-1/#post-6486486)
 * Hey, that works!
 * Also:
 *     ```
       // if two checkboxes are pressed:
   
       elseif ( $list == 6  &&  $list == 2 )
       {...}
       ```
   
 * One last question, I swear — what if no checkbox is pressed? I tried with:
 * $list == 0
 * or
 * $list == 1
 * or
 * $list == NULL
 * but none worked.
 * In both cases, the final ELSE condition in the FOREACH loop doesn’t send anything.
 * M.
 *  Plugin Author [eventualo](https://wordpress.org/support/users/eventualo/)
 * (@eventualo)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/custom-hooks-1/#post-6486487)
 * Remind that `$lists` can be: an array of list IDs and the `$list` inside foreach
   is the ID of each list, or false if subscriber didn’t check any lists.
    Before
   the foreach you should check if subscriber checked at least a list, so the updated
   code can be:
 *     ```
       $attachments = array();
   
       $subscriber = alo_em_get_subscriber( $email );
       $lists = alo_em_get_user_mailinglists( $subscriber->ID );
   
       if ( is_array( $lists ) ) {
       	foreach ( $lists as $list ) {
       		if ( $list == 1 ) { // the list ID
       			array_push($attachments, WP_CONTENT_DIR . '/profile-pics//attachment_list_1.mobi' );
       		}
       		/* else if list == 2 .... etc */
       	}
       } else {
       	// No lists selected by subscriber
       }
       ```
   
 *  Thread Starter [eupalinos](https://wordpress.org/support/users/eupalinos/)
 * (@eupalinos)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/custom-hooks-1/#post-6486488)
 * Thanks a lot, Alessandro!
 * Please, mark the thread as solved.
 * Marco.
 *  Thread Starter [eupalinos](https://wordpress.org/support/users/eupalinos/)
 * (@eupalinos)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/custom-hooks-1/#post-6486492)
 * For completion, I’m adding another way to do it, using the in_array php function:
 *     ```
       $attachments = array();
       	$subscriber = alo_em_get_subscriber( $email );
       	$lists = alo_em_get_user_mailinglists( $subscriber->ID );
   
       	// I have two subscription lists: ID 2 (English Newsletter) and ID 6 (Italian Newsletter)
       	// Each list has its own separate check button in the submission form.
   
       	// Checking if no selection is made
   
       if ( is_array( $lists ) ) {
   
       	// Checking array $lists whether double selection is made:
   
       	if(in_array('2',$lists) && in_array('6',$lists)){
       	$subject = "Welcome to the Newsletter!";
       	$body = file_get_contents(WP_CONTENT_DIR . '/uploads/html_eng.php');
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment1_eng.epub' );
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment2_eng.mobi' );
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment1_ita.epub' );
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment2_ita.mobi' );
       }	
   
       	// Checking if only the English Newsletter is selected (ID 2)
   
       elseif(in_array('2',$lists)){
       	$subject = "Welcome to the Newsletter!";
       	$body = file_get_contents(WP_CONTENT_DIR . '/uploads/html_eng.php');
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment1_eng.epub' );
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment2_eng.mobi' );
       }	
   
       	// Checking if only the Italian Newsletter is selected (ID 6)
   
       elseif(in_array('6',$lists)){
       	$subject = "Benvenuto alla Newsletter!";
       	$body = file_get_contents(WP_CONTENT_DIR . '/uploads/html_ita.php');
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment1_ita.epub' );
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment2_ita.mobi' );
       }  
   
       	// If none of the above:
   
       else {
       	$subject = "Welcome to the Newsletter!";
       	$body = file_get_contents(WP_CONTENT_DIR . '/uploads/html_eng.php');
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment1_eng.epub' );
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment2_eng.mobi' );
       }
       }
   
       	// Closing ELSE of the "no selection is made" check above.
   
       	else {
       	$subject = "Welcome to the Newsletter!";
       	$body = file_get_contents(WP_CONTENT_DIR . '/uploads/html_eng.php');
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment1_eng.epub' );
       	array_push($attachments, WP_CONTENT_DIR . '/profile-pics/attachment2_eng.mobi' );
       }
       	wp_mail( $email, $subject, $body, false, $attachments);
       ```
   
 * Thanks again and best.
 * M.

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

The topic ‘Custom Hooks’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/alo-easymail_574f4b.svg)
 * [ALO EasyMail Newsletter](https://wordpress.org/plugins/alo-easymail/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/alo-easymail/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/alo-easymail/)
 * [Active Topics](https://wordpress.org/support/plugin/alo-easymail/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/alo-easymail/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/alo-easymail/reviews/)

 * 10 replies
 * 2 participants
 * Last reply from: [eupalinos](https://wordpress.org/support/users/eupalinos/)
 * Last activity: [10 years, 8 months ago](https://wordpress.org/support/topic/custom-hooks-1/#post-6486492)
 * Status: resolved