Exemplo n.º 1
0
 /**
  * @param $list_id
  * @param $field_tag
  * @param $value
  *
  * @return string
  */
 protected function list_field($list_id, $field_tag, $value)
 {
     $field_name = $this->mailchimp->get_list_field_name_by_tag($list_id, $field_tag);
     $field_name = $field_name ? $field_name : $field_tag;
     $content = sprintf('<strong>%s</strong>: %s<br />', esc_html($field_name), esc_html($value));
     return $content;
 }
    /**
     * Send an email with a subscription summary to a given email address
     */
    private function send_email()
    {
        // bail if receiver is empty
        if ('' === $this->form_options['email_copy_receiver']) {
            return;
        }
        // email receiver
        $to = explode(',', str_replace(' ', '', $this->form_options['email_copy_receiver']));
        $form = get_post($this->form_id);
        $form_name = $form->post_title;
        // email subject
        $subject = __('New MailChimp Sign-Up', 'mailchimp-for-wp') . ' - ' . get_bloginfo('name');
        $mailchimp = new MC4WP_MailChimp();
        // build email message
        ob_start();
        ?>
		<h3>MailChimp for WordPress: <?php 
        _e('New Sign-Up', 'mailchimp-for-wp');
        ?>
</h3>
		<p><?php 
        printf(__('<strong>%s</strong> signed-up at %s on %s using the form "%s".', 'mailchimp-for-wp'), $this->data['EMAIL'], date('H:i'), date('d/m/Y'), $form_name);
        ?>
</p>
		<table cellspacing="0" cellpadding="10" border="0" style="border: 1px solid #EEEEEE;">
			<tbody>
				<?php 
        foreach ($this->lists_fields_map as $list_id => $field_data) {
            ?>
					<tr>
						<td colspan="2"><h4 style="border-bottom: 1px solid #efefef; margin-bottom: 0; padding-bottom: 5px;"><?php 
            echo __('List', 'mailchimp-for-wp') . ': ' . $mailchimp->get_list_name($list_id);
            ?>
</h4></td>
					</tr>
					<tr>
						<td><strong><?php 
            _e('Email address:', 'mailchimp-for-wp');
            ?>
</strong></td>
						<td><?php 
            echo $this->data['EMAIL'];
            ?>
</td>
					</tr>
					<?php 
            foreach ($field_data as $field_tag => $field_value) {
                if ($field_tag === 'GROUPINGS' && is_array($field_value) && count($field_value) > 0) {
                    foreach ($field_value as $grouping) {
                        $groups = implode(', ', $grouping['groups']);
                        ?>
								<tr>
									<td><strong><?php 
                        echo $mailchimp->get_list_grouping_name_by_id($list_id, $grouping['id']);
                        ?>
</strong></td>
									<td><?php 
                        echo esc_html($groups);
                        ?>
</td>
								</tr>
							<?php 
                    }
                } else {
                    $field_name = $mailchimp->get_list_field_name_by_tag($list_id, $field_tag);
                    // convert array values to comma-separated string value
                    if (is_array($field_value)) {
                        $field_value = implode(', ', $field_value);
                    }
                    ?>
							<tr>
								<td><strong><?php 
                    echo esc_html($field_name);
                    ?>
</strong></td>
								<td><?php 
                    echo esc_html($field_value);
                    ?>
</td>
							</tr>
							<?php 
                }
            }
            ?>
				<?php 
        }
        ?>
				<?php 
        if (count($this->unmapped_fields) > 0) {
            ?>
					<tr>
						<td colspan="2"><h4 style="border-bottom: 1px solid #efefef; margin-bottom: 0; padding-bottom: 5px;"><?php 
            _e('Other fields', 'mailchimp-for-wp');
            ?>
</h4></td>
					</tr>
					<?php 
            foreach ($this->unmapped_fields as $field_tag => $field_value) {
                ?>
						<tr>
							<td><strong><?php 
                echo esc_html(ucfirst(strtolower($field_tag)));
                ?>
</strong></td>
							<td><?php 
                echo esc_html($field_value);
                ?>
</td>
						</tr>
						<?php 
            }
        }
        ?>
			</tbody>
		</table>

		<?php 
        if ($this->form_options['double_optin']) {
            ?>
			<p style="color:#666;"><?php 
            printf(__('Note that you\'ve enabled double opt-in for the "%s" form. The user won\'t be added to the selected MailChimp lists until they confirm their email address.', 'mailchimp-for-wp'), $form_name);
            ?>
</p>
		<?php 
        }
        ?>
		<p style="color:#666;"><?php 
        _e('This email was auto-sent by the MailChimp for WordPress plugin.', 'mailchimp-for-wp');
        ?>
</p>
		<?php 
        $message = ob_get_contents();
        ob_end_clean();
        /**
         * @filter mc4wp_email_summary_receiver
         * @expects string|array String or array of emails
         * @param   int     $form_id        The ID of the submitted form
         * @param   string  $email          The email of the subscriber
         * @param   array   $lists_data     Additional list fields, like FNAME etc (if any)
         *
         * Use to set email addresses to send the email summary to
         */
        $receivers = apply_filters('mc4wp_email_summary_receiver', $to, $this->form_id, $this->data['EMAIL'], $this->lists_fields_map);
        /**
         * @filter mc4wp_email_summary_subject
         * @expects string|array String or array of emails
         * @param   int     $form_id        The ID of the submitted form
         * @param   string  $email          The email of the subscriber
         * @param   array   $lists_data     Additional list fields, like FNAME etc (if any)
         *
         * Use to set subject of email summaries
         */
        $subject = apply_filters('mc4wp_email_summary_subject', $subject, $this->form_id, $this->data['EMAIL'], $this->lists_fields_map);
        /**
         * @filter mc4wp_email_summary_message
         * @expects string|array String or array of emails
         * @param   int     $form_id        The ID of the submitted form
         * @param   string  $email          The email of the subscriber
         * @param   array   $lists_data     Additional list fields, like FNAME etc (if any)
         *
         * Use to set or customize message of email summaries
         */
        $message = apply_filters('mc4wp_email_summary_message', $message, $this->form_id, $this->data['EMAIL'], $this->lists_fields_map);
        // send email
        wp_mail($receivers, $subject, $message, 'Content-Type: text/html');
    }