protected static function send_email($email, $content, $subject) { $attachments = array(); $settings = TmMS_Settings::get_settings(); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $headers .= 'From: ' . (!empty($settings['name_from']) ? $settings['name_from'] : get_option("blogname")) . ' <' . $subject . '>' . "\r\n"; add_filter('wp_mail_content_type', create_function('', 'return "text/html"; ')); return wp_mail($email, $subject, $content, $headers, $attachments); }
public function activate_user() { //*** global $wpdb; $user_data = $wpdb->get_results('SELECT * FROM mail_subscriber_user_not_confirmed WHERE hash="' . $_GET['hash'] . '"', ARRAY_A); if (empty($user_data)) { wp_die(__('Such data doesn\'t exist', 'newsplus')); } $user_data = $user_data[0]; $user_name = $user_data['name']; $user_email = $user_data['email']; //*** $settings = TmMS_Settings::get_settings(); $random_password = wp_generate_password(); $user_id = wp_create_user($user_name, $random_password, $user_email); //subscribe user *********************************************************** $groups = self::get_users_groups(); $groups = array_keys($groups); update_user_meta($user_id, 'tm_mail_subscriber_user_groups', $groups); //************************************************************************** $subject = !isset($settings['new_user_registration_mail_subject']) ? __("User subscription", 'newsplus') : $settings['new_user_registration_mail_subject']; $content = !isset($settings['new_user_registration_text']) ? __("Hello __USERNAME__! Your password is: __PASSWORD__", 'newsplus') : $settings['new_user_registration_text']; //*** $content = str_replace("__USERNAME__", $user_name, $content); $content = str_replace("__PASSWORD__", $random_password, $content); //*** if (self::send_email($user_email, $content, $subject)) { $wpdb->delete('mail_subscriber_user_not_confirmed', array('hash' => $_GET['hash'])); $settings = TmMS_Settings::get_settings(); if (wp_authenticate($user_name, $random_password)) { $credentials['user_login'] = $user_name; $credentials['user_password'] = $random_password; $credentials['remember'] = true; $user = wp_signon($credentials, false); if (is_wp_error($user)) { wp_die(__('Wrong data', THEMEMAKERS_THEME_FOLDER_NAME)); } } ?> <script type="text/javascript"> alert('<?php _e('Thank you for signing up. Your e-mail address has been successfully added to our subscription list!', 'newsplus'); ?> '); window.location = '<?php echo home_url() . '/?p=' . $settings['user_subscribe_page_id']; ?> '; </script> <?php } else { ?> <script type="text/javascript"> alert('<?php _e('Server error. Please try again later.', 'newsplus'); ?> '); </script> <?php } }
public function send_post_one_letter() { $user_id = intval($_REQUEST['user_id']); $tpl_id = intval($_REQUEST['tpl_id']); $categories = $_REQUEST['categories']; $posts_in_heap = $this->get_posts_in_heap(); //*** filter $posts_in_heap by $categories, if empty send no letter $posts_to_letter = array(); if (!empty($posts_in_heap)) { foreach ($posts_in_heap as $post_id) { $post_categories = wp_get_post_categories($post_id, array('fields' => 'ids')); if (array_intersect($categories, $post_categories)) { $posts_to_letter[] = $post_id; } } } //*** //order posts by id as their order in admin panel $tmp = array(); foreach ($_REQUEST['posts_in_order'] as $post_id) { if (in_array($post_id, $posts_to_letter)) { $tmp[] = $post_id; } } $posts_to_letter = $tmp; //*** if (!empty($posts_to_letter)) { $settings = TmMS_Settings::get_settings(); //*** $user = get_userdata($user_id); $email = $user->user_email; $subject = $settings['default_email_subject']; //*** $posts = array(); foreach ($posts_to_letter as $post_id) { $posts[] = get_post($post_id); } //*** $data = array('user_name' => $user->user_nicename, 'posts' => $posts); //replacing snippets by values $content = get_post_field('post_content', $tpl_id); $content = str_replace('<p>__POSTS_CYCLE_START__</p>', '__POSTS_CYCLE_START__', $content); $content = str_replace('<p>__POSTS_CYCLE_END__</p>', '__POSTS_CYCLE_END__', $content); $content = str_replace('__POSTS_CYCLE_START__', '<?php foreach ($posts as $post) : ?>', $content); $content = str_replace('__POSTS_CYCLE_END__', '<?php endforeach; ?>', $content); $content = str_replace('__POST_TITLE__', '<?php echo get_the_title($post->ID); ?>', $content); $content = str_replace('__POST_CONTENT__', '<?php echo str_replace(\']]>\', \']]>\', apply_filters(\'the_content\', $post->post_content)); ?>', $content); $content = str_replace('__POST_PERMALINK__', '<?php echo get_permalink($post->ID); ?>', $content); $content = str_replace('__POST_EXCERPT__', '<?php echo $post->post_excerpt; ?>', $content); $content = str_replace('__USER_NAME__', '<?php echo $user_name; ?>', $content); $content = str_replace('__CURRENT_DATA__', '<?php echo date("d-m-Y"); ?>', $content); //*** $buffer_path = THEMEMAKERS_MAIL_SUBSCRIBER_PATH . 'views/buffer.php'; file_put_contents($buffer_path, $content); $content = $this->draw_html('buffer', $data); //*** self::send_email($email, $content, $subject); } exit; }
public function send_one_letter() { $user_id = (int) $_REQUEST['user_id']; $post_id = (int) $_REQUEST['post_id']; $settings = TmMS_Settings::get_settings(); $site_url = site_url(); //*** $email = ""; if ($user_id != 0) { $email = get_user_option('user_email', $user_id); } else { $email = $_REQUEST['email']; } //*** $content = $this->db_quotes_shield(array('content' => $_REQUEST['content'])); $content = $content['content']; //change links for stat $pattern = '#href=([\'"]?)((?(?<![\'"])[^>\\s]+|.+?(?=\\1)))\\1#si'; $links_array = array(); $processed_links_array = array(); if (preg_match_all($pattern, $content, $links_array)) { foreach ($links_array[0] as $link) { if (!empty($link) and $link != '#') { //$link = str_replace('"', '', $link); //$link = str_replace("'", '', $link); $link = str_replace("href=", '', $link); //*** if (!in_array($link, $processed_links_array) and !empty($link) and $link != '#') { $c = substr_count($link, $site_url); if ($c > 0) { //$content=preg_replace($pattern, TmMS_Statistic::get_letter_link_url($link, array('user_id' => $user_id, 'mail_id' => $post_id)), $content); $content = str_replace($link, TmMS_Statistic::get_letter_link_url($link, array('user_id' => $user_id > 0 ? $user_id : uniqid(), 'mail_id' => $post_id)) . '"', $content); $processed_links_array[] = $link; } } //*** } } $content = str_replace('"?', '?', $content); } //**** add unsubscribe link if ($user_id > 0) { $content .= "<br />"; $content .= '<center>' . __("To stop receiving these emails, you may", 'newsplus') . ": " . "<a href='" . home_url() . "/?p=" . $settings['user_subscribe_page_id'] . "'>" . __('Manage your subscriptions', 'newsplus') . "</a></center>"; } //************************* $attachments = array(); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; //$headers .= 'To: <' . $email . '>' . "\r\n"; $headers .= 'From: ' . (!empty($settings['name_from']) ? $settings['name_from'] : get_option("blogname")) . ' <' . (!empty($settings['senders_mail_address']) ? $settings['senders_mail_address'] : get_option("admin_email")) . '>' . "\r\n"; add_filter('wp_mail_content_type', create_function('', 'return "text/html"; ')); $result_data = array(); $result_data['error'] = ""; $subject = get_post_meta($post_id, 'email_subject', true); if (!wp_mail($email, !empty($subject) ? $subject : $settings['default_email_subject'], $content, $headers, $attachments)) { $result_data['error'] = "Email for " . $email . " has not been sent"; } else { $stat_data = array('user_id' => $user_id, 'mail_id' => $post_id, 'groups' => implode(',', $_REQUEST['subscribe_groups']), 'time' => time()); $this->statistic->update_stat('sent', $stat_data); $this->statistic->add_mail_stat_data($post_id, array()); } echo json_encode($result_data); exit; }
if (!empty($instance['title'])) { ?> <h3 class="widget-title"><?php echo $instance['title']; ?> </h3> <?php } ?> <?php if (is_user_logged_in()) { ?> <?php //$user = wp_get_current_user(); $settings = TmMS_Settings::get_settings(); ?> <a href="<?php echo get_permalink($settings['user_subscribe_page_id']); ?> "><?php _e('Manage your subscriptions', 'newsplus'); ?> </a><br /> <?php } else { ?> <p><?php echo $instance['text']; ?>