/**
  * @return bool
  */
 public function process()
 {
     $api = mc4wp_get_api();
     do_action('mc4wp_before_subscribe', $this->data['EMAIL'], $this->data, 0);
     $result = false;
     $email_type = $this->get_email_type();
     // loop through selected lists
     foreach ($this->list_fields_map as $list_id => $list_field_data) {
         // allow plugins to alter merge vars for each individual list
         $list_merge_vars = $this->get_list_merge_vars($list_id, $list_field_data);
         // send a subscribe request to MailChimp for each list
         $result = $api->subscribe($list_id, $this->data['EMAIL'], $list_merge_vars, $email_type, $this->form->settings['double_optin'], $this->form->settings['update_existing'], $this->form->settings['replace_interests'], $this->form->settings['send_welcome']);
         do_action('mc4wp_subscribe', $this->data['EMAIL'], $list_id, $list_merge_vars, $result, 'form', 'form', 0);
     }
     do_action('mc4wp_after_subscribe', $this->data['EMAIL'], $this->data, 0, $result);
     // did we succeed in subscribing with the parsed data?
     if (!$result) {
         $this->message_type = $api->get_error_code() === 214 ? 'already_subscribed' : 'error';
         $this->mailchimp_error = $api->get_error_message();
     } else {
         $this->message_type = 'subscribed';
         // store user email in a cookie
         MC4WP_Tools::remember_email($this->data['EMAIL']);
     }
     $this->success = $result;
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Returns text with {variables} replaced.
  *
  * @param string $string
  * @param array $additional_replacements
  * @param array $list_ids Array of list ID's (needed if {subscriber_count} is set
  * @param string $output
  *
  * @return string $text       The text with {variables} replaced.
  * replaced.
  */
 public static function replace_variables($string, $additional_replacements = array(), $list_ids = array(), $output = 'string')
 {
     self::$replacement_output = $output;
     // replace general vars
     $replacements = array('{ip}' => self::get_client_ip(), '{current_url}' => mc4wp_get_current_url(), '{current_path}' => !empty($_SERVER['REQUEST_URI']) ? esc_html($_SERVER['REQUEST_URI']) : '', '{date}' => date('m/d/Y'), '{time}' => date('H:i:s'), '{language}' => defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : get_locale(), '{email}' => self::get_known_email(), '{user_email}' => '', '{user_firstname}' => '', '{user_lastname}' => '', '{user_name}' => '', '{user_id}' => '');
     // setup replacements for logged-in users
     if (is_user_logged_in() && ($user = wp_get_current_user()) && $user instanceof WP_User) {
         // logged in user, replace vars by user vars
         $replacements['{user_email}'] = $user->user_email;
         $replacements['{user_firstname}'] = $user->first_name;
         $replacements['{user_lastname}'] = $user->last_name;
         $replacements['{user_name}'] = $user->display_name;
         $replacements['{user_id}'] = $user->ID;
     }
     // merge with additional replacements
     $replacements = array_merge($replacements, $additional_replacements);
     // subscriber count? only fetch these if the tag is actually used
     if (stripos($string, '{subscriber_count}') !== false) {
         $mailchimp = new MC4WP_MailChimp();
         $subscriber_count = $mailchimp->get_subscriber_count($list_ids);
         $replacements['{subscriber_count}'] = $subscriber_count;
     }
     // encode replacements when output type is set to 'url'
     if (self::$replacement_output === 'url') {
         $replacements = urlencode_deep($replacements);
     }
     // perform the replacement
     $string = str_ireplace(array_keys($replacements), array_values($replacements), $string);
     // replace dynamic variables
     if (stristr($string, '{data_') !== false) {
         $string = preg_replace_callback('/\\{data_([\\w-.]+)( default=\\"([^"]*)\\"){0,1}\\}/', array('MC4WP_Tools', 'replace_request_data_variables'), $string);
     }
     return $string;
 }
    /**
     * Output the widget code
     */
    public function output()
    {
        $items = $this->logger->find(array('limit' => 5, 'include_errors' => false));
        if (empty($items)) {
            echo '<p>' . __("No log entries found.", 'mailchimp-for-wp') . '</p>';
        } else {
            ?>
			<style type="text/css" scoped>
				.mc4wp-dashboard-table {
					table-layout: fixed;
					width: 100%;
				}

				.mc4wp-dashboard-table th {
					text-align: left;
				}

				.mc4wp-dashboard-table td {
					overflow: hidden;
				}
			</style>

			<table class="mc4wp-dashboard-table">
			<thead>
				<tr>
					<th><?php 
            _e('Email address', 'mailchimp-for-wp');
            ?>
</th>
					<th><?php 
            _e('Date', 'mailchimp-for-wp');
            ?>
</th>
				</tr>
			</thead>
			<?php 
            foreach ($items as $item) {
                ?>
				<tr>
					<td><a href="<?php 
                echo admin_url('admin.php?page=mailchimp-for-wp-reports&tab=log#item-' . $item->ID);
                ?>
"><?php 
                echo esc_html($item->email);
                ?>
</a></td>
					<td><?php 
                echo MC4WP_Tools::mysql_datetime_to_local_datetime($item->datetime, 'M, j H:i');
                ?>
</td>
				</tr>
			<?php 
            }
            ?>
			</table>
			<?php 
        }
        echo '<p><a href="' . admin_url('admin.php?page=mailchimp-for-wp-reports&tab=log') . '">' . __('View entire log', 'mailchimp-for-wp') . '</a></p>';
    }
Exemplo n.º 4
0
 /**
  * @param string $element_id
  * @param array $attributes
  * @param string $response_html
  * @return string
  */
 public function get_visible_fields($element_id, array $attributes = array(), $response_html = '')
 {
     $replacements = array('{n}' => $element_id, '{response}' => $response_html);
     $visible_fields = MC4WP_Tools::replace_variables($this->content, $replacements, array_values($this->settings['lists']));
     // insert captcha
     if (function_exists('cptch_display_captcha_custom')) {
         $captcha_fields = '<input type="hidden" name="_mc4wp_has_captcha" value="1" /><input type="hidden" name="cntctfrm_contact_action" value="true" />' . cptch_display_captcha_custom();
         $visible_fields = str_ireplace(array('{captcha}', '[captcha]'), $captcha_fields, $visible_fields);
     }
     /**
      * @filter mc4wp_form_content
      * @param int $form_id The ID of the form that is being shown
      * @expects string
      *
      * Can be used to customize the content of the form mark-up, eg adding additional fields.
      */
     $visible_fields = (string) apply_filters('mc4wp_form_content', $visible_fields, $this->ID);
     return $visible_fields;
 }
 /**
  * Adds global fields like OPTIN_IP, MC_LANGUAGE, OPTIN_DATE, etc to the list of user-submitted field data.
  *
  * @param string $list_id
  * @param array $list_field_data
  * @return array
  */
 protected function get_list_merge_vars($list_id, $list_field_data)
 {
     $merge_vars = array();
     // add OPTIN_IP, we do this here as the user shouldn't be allowed to set this
     $merge_vars['OPTIN_IP'] = MC4WP_Tools::get_client_ip();
     // make sure MC_LANGUAGE matches the requested format. Useful when getting the language from WPML etc.
     if (isset($this->map->global_fields['MC_LANGUAGE'])) {
         $merge_vars['MC_LANGUAGE'] = strtolower(substr($this->map->global_fields['MC_LANGUAGE'], 0, 2));
     }
     $merge_vars = array_merge($merge_vars, $list_field_data);
     /**
      * @filter `mc4wp_merge_vars`
      * @expects array
      * @param int $form_id
      * @param string $list_id
      *
      * Can be used to filter the merge variables sent to a given list
      */
     $merge_vars = (array) apply_filters('mc4wp_merge_vars', $merge_vars, 0, $list_id);
     return $merge_vars;
 }
 /**
  * Load scripts and stylesheet on MailChimp for WP Admin pages
  *
  * @return bool
  */
 public function enqueue_assets()
 {
     global $wp_scripts;
     $prefix = 'mailchimp-for-wp';
     // only load asset files on the MailChimp for WordPress settings pages
     if (empty($_GET['page']) || strpos($_GET['page'], $prefix) !== 0) {
         return false;
     }
     $page = ltrim(substr($_GET['page'], strlen($prefix)), '-');
     $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
     // css
     wp_register_style('mc4wp-admin', MC4WP_PLUGIN_URL . 'assets/css/admin-styles' . $suffix . '.css', array(), MC4WP_VERSION);
     wp_enqueue_style('mc4wp-admin');
     // js
     wp_register_script('es5-shim', MC4WP_PLUGIN_URL . 'assets/js/third-party/es5-shim.min.js', array(), MC4WP_VERSION);
     $wp_scripts->add_data('es5-shim', 'conditional', 'lt IE 9');
     // @todo: eventually get rid of jQuery here
     wp_register_script('mc4wp-admin', MC4WP_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'es5-shim'), MC4WP_VERSION, true);
     wp_enqueue_script(array('jquery', 'es5-shim', 'mc4wp-admin'));
     wp_localize_script('mc4wp-admin', 'mc4wp_vars', array('mailchimp' => array('lists' => $this->mailchimp->get_lists()), 'countries' => MC4WP_Tools::get_countries(), 'l10n' => array('pro_only' => __('This is a pro-only feature. Please upgrade to the premium version to be able to use it.', 'mailchimp-for-wp'))));
     /**
      * Hook to enqueue your own custom assets on the MailChimp for WordPress setting pages.
      *
      * @since 3.0
      *
      * @param string $suffix
      * @param string $page
      */
     do_action('mc4wp_admin_enqueue_assets', $suffix, $page);
     return true;
 }
Exemplo n.º 7
0
 /**
  * Makes a subscription request
  *
  * @param string $email
  * @param array $merge_vars
  * @param string $type
  * @param int $related_object_id
  * @return string|boolean
  */
 protected function subscribe($email, array $merge_vars = array(), $type = '', $related_object_id = 0)
 {
     $type = '' !== $type ? $type : $this->type;
     $api = mc4wp_get_api();
     $opts = $this->get_options();
     $lists = $this->get_lists();
     if (empty($lists)) {
         // show helpful error message to admins, but only if not using ajax
         if ($this->show_error_messages()) {
             wp_die('<h3>' . __('MailChimp for WordPress - Error', 'mailchimp-for-wp') . '</h3>' . '<p>' . sprintf(__('Please select a list to subscribe to in the <a href="%s">checkbox settings</a>.', 'mailchimp-for-wp'), admin_url('admin.php?page=mailchimp-for-wp-checkbox-settings')) . '</p>' . '<p style="font-style:italic; font-size:12px;">' . __('This message is only visible to administrators for debugging purposes.', 'mailchimp-for-wp') . '</p>', __('MailChimp for WordPress - Error', 'mailchimp-for-wp'), array('back_link' => true));
         }
         return 'no_lists_selected';
     }
     $merge_vars = MC4WP_Tools::guess_merge_vars($merge_vars);
     // set ip address
     if (!isset($merge_vars['OPTIN_IP'])) {
         $merge_vars['OPTIN_IP'] = MC4WP_Tools::get_client_ip();
     }
     $result = false;
     /**
      * @filter `mc4wp_merge_vars`
      * @expects array
      * @param array $merge_vars
      * @param string $type
      *
      * Use this to filter the final merge vars before the request is sent to MailChimp
      */
     $merge_vars = apply_filters('mc4wp_merge_vars', $merge_vars, $type);
     /**
      * @filter `mc4wp_merge_vars`
      * @expects string
      * @param string $email_type
      *
      * Use this to change the email type this users should receive
      */
     $email_type = apply_filters('mc4wp_email_type', 'html');
     /**
      * @action `mc4wp_before_subscribe`
      * @param string $email
      * @param array $merge_vars
      *
      * Runs before the request is sent to MailChimp
      */
     do_action('mc4wp_before_subscribe', $email, $merge_vars);
     foreach ($lists as $list_id) {
         $result = $api->subscribe($list_id, $email, $merge_vars, $email_type, $opts['double_optin'], $opts['update_existing'], true, $opts['send_welcome']);
         do_action('mc4wp_subscribe', $email, $list_id, $merge_vars, $result, 'checkbox', $type, $related_object_id);
     }
     /**
      * @action `mc4wp_after_subscribe`
      * @param string $email
      * @param array $merge_vars
      * @param boolean $result
      *
      * Runs after the request is sent to MailChimp
      */
     do_action('mc4wp_after_subscribe', $email, $merge_vars, $result);
     // if result failed, show error message (only to admins for non-AJAX)
     if ($result !== true && $api->has_error()) {
         // log error
         error_log(sprintf('MailChimp for WordPres (%s): %s', date('Y-m-d H:i:s'), $this->type, $api->get_error_message()));
         if ($this->show_error_messages()) {
             wp_die('<h3>' . __('MailChimp for WordPress - Error', 'mailchimp-for-wp') . '</h3>' . '<p>' . __('The MailChimp server returned the following error message as a response to our sign-up request:', 'mailchimp-for-wp') . '</p>' . '<pre>' . $api->get_error_message() . '</pre>' . '<p>' . __('This is the data that was sent to MailChimp:', 'mailchimp-for-wp') . '</p>' . '<strong>' . __('Email address:', 'mailchimp-for-wp') . '</strong>' . '<pre>' . esc_html($email) . '</pre>' . '<strong>' . __('Merge variables:', 'mailchimp-for-wp') . '</strong>' . '<pre>' . esc_html(print_r($merge_vars, true)) . '</pre>' . '<p style="font-style:italic; font-size:12px;">' . __('This message is only visible to administrators for debugging purposes.', 'mailchimp-for-wp') . '</p>', __('MailChimp for WordPress - Error', 'mailchimp-for-wp'), array('back_link' => true));
         }
     }
     return $result;
 }
 /**
  * Makes a subscription request
  *
  * @param string $email
  * @param array $merge_vars
  * @param int $related_object_id
  * @return string|boolean
  */
 protected function subscribe($email, array $merge_vars = array(), $related_object_id = null)
 {
     $lists = $this->get_lists();
     if (empty($lists)) {
         error_log(sprintf("MailChimp for WordPress: No lists selected for the %s integration.", $this->name));
         return false;
     }
     $merge_vars = MC4WP_Tools::guess_merge_vars($merge_vars);
     if (!isset($merge_vars['OPTIN_IP'])) {
         $merge_vars['OPTIN_IP'] = MC4WP_tools::get_client_ip();
     }
     $result = false;
     $config = array('double_optin' => $this->options['double_optin'], 'update_existing' => $this->options['update_existing'], 'send_welcome' => $this->options['send_welcome']);
     $extra = array('related_object_id' => $related_object_id, 'referer' => $_SERVER['HTTP_REFERER'], 'type' => 'integration', 'integration' => $this->name);
     foreach ($lists as $list_id) {
         $request = new MC4WP_API_Request('subscribe', $list_id, $email, $merge_vars, $config, $extra);
         /** @var MC4WP_API_Response $response */
         $response = $request->process();
     }
     if (!$response->success) {
         error_log(sprintf('MailChimp for WP: Subscribe request from %s integration failed. The following error was returned by the MailChimp API. "%s"', $this->name, $response->error));
     }
     return $result;
 }
 /**
  * Returns the HTML for success or error messages
  *
  * @return string
  */
 public function get_response_html()
 {
     // get all form messages
     $messages = $this->form->get_messages();
     // retrieve correct message
     $message = isset($messages[$this->message_type]) ? $messages[$this->message_type] : $messages['error'];
     // replace variables in message text
     $message['text'] = MC4WP_Tools::replace_variables($message['text'], array(), array_values($this->get_lists()));
     $html = '<div class="mc4wp-alert mc4wp-' . esc_attr($message['type']) . '">' . $message['text'] . '</div>';
     // show additional MailChimp API errors to administrators
     if (!$this->success && current_user_can('manage_options')) {
         if ('' !== $this->mailchimp_error) {
             $html .= '<div class="mc4wp-alert mc4wp-error"><strong>Admin notice:</strong> ' . $this->mailchimp_error . '</div>';
         }
     }
     return $html;
 }
Exemplo n.º 10
0
 /**
  * Prepare the requests this form creates
  *
  * @return bool
  */
 public function prepare()
 {
     $lists = $this->get_lists();
     $merge_vars = $this->parse_merge_vars();
     $email = $this->data['EMAIL'];
     $config = array('email_type' => $this->get_email_type(), 'ip' => MC4WP_Tools::get_client_ip());
     $extra = array('related_object_id' => $this->form->ID, 'referer' => $_SERVER['HTTP_REFERER'], 'type' => 'form');
     // create a request object for each list
     foreach ($lists as $list_id) {
         $request = MC4WP_API_Request::create($this->config['action'], $list_id, $email, $merge_vars, $config, $extra);
         $this->requests[] = $request;
     }
     return true;
 }
Exemplo n.º 11
0
 /**
  * Retrieves the URL of the current WordPress page
  *
  * @return  string  The current URL, escaped for safe usage inside attributes.
  */
 function mc4wp_get_current_url()
 {
     return MC4WP_Tools::get_current_url();
 }
Exemplo n.º 12
0
 public function column_datetime($item)
 {
     $date = MC4WP_Tools::mysql_datetime_to_local_datetime($item->datetime);
     return esc_html($date);
 }
    /**
     * Build email message
     *
     * @return string
     */
    public function build_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->request->user_data['EMAIL'], date(get_option('time_format')), date(get_option('date_format')), $this->form->name);
        ?>
</p>
		<table cellspacing="0" cellpadding="10" border="0" style="border: 1px solid #EEEEEE;">
			<tbody>
			<?php 
        foreach ($this->request->map->list_fields 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') . ': ' . $this->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->request->user_data['EMAIL'];
            ?>
</td>
				</tr>
				<?php 
            foreach ($field_data as $field_tag => $field_value) {
                if ($field_tag === 'GROUPINGS' && is_array($field_value)) {
                    foreach ($field_value as $grouping) {
                        $groups = implode(', ', $grouping['groups']);
                        ?>
							<tr>
								<td><strong><?php 
                        echo $this->mailchimp->get_list_grouping_name($list_id, $grouping['id']);
                        ?>
:</strong></td>
								<td><?php 
                        echo esc_html($groups);
                        ?>
</td>
							</tr>
						<?php 
                    }
                } else {
                    $field_name = $this->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->request->map->custom_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->request->map->custom_fields as $field_tag => $field_value) {
                // 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_tag);
                ?>
:</strong></td>
						<td><?php 
                echo esc_html($field_value);
                ?>
</td>
					</tr>
				<?php 
            }
            ?>
			<?php 
        }
        ?>

			</tbody>
		</table>
		<br />

		<p><?php 
        printf(__('User subscribed from %s from IP %s.', 'mailchimp-for-wp'), esc_html($this->request->http_referer), MC4WP_Tools::get_client_ip());
        ?>
</p>

		<?php 
        if ($this->form->settings['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'), $this->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 
        return ob_get_clean();
    }
Exemplo n.º 14
0
 /**
  * Process the request
  *
  * @return bool
  */
 public function process()
 {
     $api = mc4wp_get_api();
     if ($this->type === 'subscribe') {
         $success = $api->subscribe($this->list_id, $this->email, $this->merge_vars, $this->config['email_type'], $this->config['double_optin'], $this->config['update_existing'], $this->config['replace_interests'], $this->config['send_welcome']);
     } else {
         $success = $api->unsubscribe($this->list_id, $this->email, $this->config['send_goodbye'], $this->config['send_notification'], $this->config['delete_member']);
     }
     if ($success) {
         // store user email in a cookie
         // todo: decouple this
         MC4WP_Tools::remember_email($this->email);
     }
     // convert API response to our own response object
     $response = new MC4WP_API_Response($this->type, $success, $api->get_last_response());
     $this->response = $response;
     /**
      * @api
      * @action 'mc4wp_request_processed'
      *
      * @param Request
      * @param Response
      */
     do_action('mc4wp_request_processed', $this, $response);
     return $response;
 }
Exemplo n.º 15
0
 /**
  * @param $item
  * @param $column_name
  *
  * @return string
  */
 public function column_default($item, $column_name)
 {
     switch ($column_name) {
         case 'success':
             $color = $item->success ? 'green' : 'red';
             $icon = $item->success ? '&#10003;' : '&#10006;';
             return sprintf('<span style="color: %s;">%s</span>', $color, $icon);
             break;
         case 'datetime':
             $date = MC4WP_Tools::mysql_datetime_to_local_datetime($item->{$column_name});
             return esc_html($date);
             break;
         default:
             return '';
             break;
     }
 }
Exemplo n.º 16
0
    /**
     * Send an email with a subscription summary to a given email address
     */
    protected function send_email()
    {
        // bail if receiver is empty
        if ('' === $this->form->settings['email_copy_receiver']) {
            return;
        }
        // email receiver
        $to = explode(',', str_replace(' ', '', $this->form->settings['email_copy_receiver']));
        // email subject
        $subject = __('New MailChimp Sign-Up', 'mailchimp-for-wp') . ' - ' . get_bloginfo('name');
        $mailchimp = new MC4WP_MailChimp();
        $referer = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $_SERVER['REQUEST_URI'];
        // 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->user_data['EMAIL'], date('H:i'), date('d/m/Y'), $this->form->name);
        ?>
</p>
		<table cellspacing="0" cellpadding="10" border="0" style="border: 1px solid #EEEEEE;">
			<tbody>
			<?php 
        foreach ($this->list_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->user_data['EMAIL'];
            ?>
</td>
				</tr>
				<?php 
            foreach ($field_data as $field_tag => $field_value) {
                if ($field_tag === 'GROUPINGS' && is_array($field_value)) {
                    foreach ($field_value as $grouping) {
                        $groups = implode(', ', $grouping['groups']);
                        ?>
							<tr>
								<td><strong><?php 
                        echo $mailchimp->get_list_grouping_name($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) {
                // 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_tag);
                ?>
</strong></td>
						<td><?php 
                echo esc_html($field_value);
                ?>
</td>
					</tr>
					<?php 
            }
            ?>
			<?php 
        }
        ?>

			</tbody>
		</table>

		<p><?php 
        printf(__('User subscribed from %s from IP %s.', 'mailchimp-for-wp'), esc_html($referer), MC4WP_Tools::get_client_ip());
        ?>
</p>

		<?php 
        if ($this->form->settings['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'), $this->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->user_data['EMAIL'], $this->list_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->user_data['EMAIL'], $this->list_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->user_data['EMAIL'], $this->list_fields_map);
        // send email
        wp_mail($receivers, $subject, $message, 'Content-Type: text/html');
    }
 /**
  * Load scripts and stylesheet on MailChimp for WP Admin pages
  *
  * @return bool
  */
 public function enqueue_assets()
 {
     global $wp_scripts;
     if (!$this->tools->on_plugin_page()) {
         return false;
     }
     $opts = mc4wp_get_options();
     $page = $this->tools->get_plugin_page();
     $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
     // css
     wp_register_style('mc4wp-admin', MC4WP_PLUGIN_URL . 'assets/css/admin-styles' . $suffix . '.css', array(), MC4WP_VERSION);
     wp_enqueue_style('mc4wp-admin');
     // js
     wp_register_script('es5-shim', MC4WP_PLUGIN_URL . 'assets/js/third-party/es5-shim.min.js', array(), MC4WP_VERSION);
     $wp_scripts->add_data('es5-shim', 'conditional', 'lt IE 9');
     // TODO: eventually get rid of jQuery here
     wp_register_script('mc4wp-admin', MC4WP_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'es5-shim'), MC4WP_VERSION, true);
     wp_enqueue_script(array('jquery', 'es5-shim', 'mc4wp-admin'));
     wp_localize_script('mc4wp-admin', 'mc4wp_vars', array('mailchimp' => array('api_connected' => !empty($opts['api_key']), 'lists' => $this->mailchimp->get_cached_lists()), 'countries' => MC4WP_Tools::get_countries(), 'i18n' => array('pro_only' => __('This is a pro-only feature. Please upgrade to the premium version to be able to use it.', 'mailchimp-for-wp'), 'renew_mailchimp_lists' => __('Renew MailChimp lists', 'mailchimp-for-wp'), 'fetching_mailchimp_lists' => __('Fetching MailChimp lists', 'mailchimp-for-wp'), 'fetching_mailchimp_lists_done' => __('Done! MailChimp lists renewed.', 'mailchimp-for-wp'), 'fetching_mailchimp_lists_can_take_a_while' => __('This can take a while if you have many MailChimp lists.', 'mailchimp-for-wp'))));
     /**
      * Hook to enqueue your own custom assets on the MailChimp for WordPress setting pages.
      *
      * @since 3.0
      *
      * @param string $suffix
      * @param string $page
      */
     do_action('mc4wp_admin_enqueue_assets', $suffix, $page);
     return true;
 }
Exemplo n.º 18
0
 /**
  * Try to guess the values of various fields, if not given.
  */
 protected function guess_fields()
 {
     // add some data to the posted data, like FNAME and LNAME
     $this->user_data = MC4WP_Tools::guess_merge_vars($this->user_data);
 }