public static function cp_mp_order_notification_body($content, $order)
 {
     if ('3.0' === self::get_base() && !is_object($order) && !empty($order)) {
         $order = new MP_Order($order);
     }
     if (cp_get_order_course_id($order->ID)) {
         $course_id = cp_get_order_course_id($order->ID);
         $course = new Course($course_id);
         $tags = array('CUSTOMER_NAME', 'BLOG_NAME', 'LOGIN_ADDRESS', 'WEBSITE_ADDRESS', 'COURSE_ADDRESS', 'COURSE_TITLE', 'ORDER_ID', 'ORDER_STATUS_URL');
         $course_title = '';
         $course_address = '';
         $order_name = '';
         $tracking_url = '';
         switch (self::get_base()) {
             case '3.0':
                 $cart = $order->get_cart();
                 $items = $cart->get_items();
                 $order_post = get_post($order->ID);
                 $course_title = '';
                 $course_address = '';
                 $order_name = $order->get_meta('mp_billing_info->first_name') . ' ' . $order->get_meta('mp_billing_info->last_name');
                 $counter = 0;
                 foreach ($items as $product_id => $qty) {
                     $counter += 1;
                     $course_id = (int) get_post_meta($product_id, 'course_id', true);
                     $course_title .= get_post_field('post_title', $course_id);
                     $course_address .= get_permalink($course_id);
                     if (count($items) > 0 && $counter !== count($items)) {
                         $course_title .= ', ';
                         $course_address .= ', ';
                     }
                 }
                 $tracking_url = apply_filters('wpml_marketpress_tracking_url', mp_orderstatus_link(false, true) . $order_post->post_title . '/');
                 break;
             case '2.0':
                 $order_name = $order->mp_shipping_info['name'];
                 $course_address = $course->get_permalink();
                 $course_title = $course->details->post_title;
                 $tracking_url = apply_filters('wpml_marketpress_tracking_url', mp_orderstatus_link(false, true) . $order->post_title . '/');
                 break;
         }
         $tags_replaces = array($order_name, get_bloginfo(), cp_student_login_address(), home_url(), $course_address, $course_title, $order->ID, $tracking_url);
         $message = coursepress_get_mp_order_content_email();
         $message = str_replace($tags, $tags_replaces, $message);
         add_filter('wp_mail_from', 'my_mail_from_function', 99);
         if (!function_exists('my_mail_from_function')) {
             function my_mail_from_function($email)
             {
                 return coursepress_get_mp_order_from_email();
             }
         }
         add_filter('wp_mail_from_name', 'my_mail_from_name_function', 99);
         if (!function_exists('my_mail_from_name_function')) {
             function my_mail_from_name_function($name)
             {
                 return coursepress_get_mp_order_from_name();
             }
         }
         return $message;
     } else {
         return $content;
     }
 }
        function course_signup($atts)
        {
            ob_start();
            $allowed = array('signup', 'login');
            extract(shortcode_atts(array('page' => isset($_REQUEST['page']) ? $_REQUEST['page'] : '', 'failed_login_text' => __('Invalid login.', 'cp'), 'failed_login_class' => 'red', 'logout_url' => '', 'signup_tag' => 'h3', 'signup_title' => __('Signup', 'cp'), 'login_tag' => 'h3', 'login_title' => __('Login', 'cp'), 'signup_url' => '', 'login_url' => '', 'redirect_url' => ''), $atts, 'course_signup'));
            $failed_login_text = sanitize_text_field($failed_login_text);
            $failed_login_class = sanitize_html_class($failed_login_class);
            $logout_url = esc_url_raw($logout_url);
            $signup_tag = sanitize_html_class($signup_tag);
            $signup_title = sanitize_text_field($signup_title);
            $login_tag = sanitize_html_class($login_tag);
            $login_title = sanitize_text_field($login_title);
            $signup_url = esc_url_raw($signup_url);
            $redirect_url = esc_url_raw($redirect_url);
            $page = in_array($page, $allowed) ? $page : 'signup';
            $signup_prefix = empty($signup_url) ? '&' : '?';
            $login_prefix = empty($login_url) ? '&' : '?';
            $signup_url = empty($signup_url) ? CoursePress::instance()->get_signup_slug(true) : $signup_url;
            $login_url = empty($login_url) ? CoursePress::instance()->get_login_slug(true) : $login_url;
            if (!empty($redirect_url)) {
                $signup_url = $signup_url . $signup_prefix . 'redirect_url=' . urlencode($redirect_url);
                $login_url = $login_url . $login_prefix . 'redirect_url=' . urlencode($redirect_url);
            }
            if (!empty($_POST['redirect_url'])) {
                $signup_url = CoursePress::instance()->get_signup_slug(true) . '?redirect_url=' . $_POST['redirect_url'];
                $login_url = CoursePress::instance()->get_login_slug(true) . '?redirect_url=' . $_POST['redirect_url'];
            }
            //Set a cookie now to see if they are supported by the browser.
            setcookie(TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN);
            if (SITECOOKIEPATH != COOKIEPATH) {
                setcookie(TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN);
            }
            //Set a redirect for the logout form
            if (!empty($logout_url)) {
                update_option('cp_custom_login_url', $logout_url);
            }
            $form_message = '';
            $form_message_class = '';
            // Attempt a login if submitted
            if (isset($_POST['log']) && isset($_POST['pwd'])) {
                $auth = wp_authenticate_username_password(null, $_POST['log'], $_POST['pwd']);
                if (!is_wp_error($auth)) {
                    // if( defined('DOING_AJAX') && DOING_AJAX ) { cp_write_log('doing ajax'); }
                    $user = get_user_by('login', $_POST['log']);
                    $user_id = $user->ID;
                    wp_set_current_user($user_id);
                    wp_set_auth_cookie($user_id);
                    if (!empty($redirect_url)) {
                        wp_redirect(urldecode($redirect_url));
                    } else {
                        wp_redirect(CoursePress::instance()->get_student_dashboard_slug(true));
                    }
                    exit;
                } else {
                    $form_message = $failed_login_text;
                    $form_message_class = $failed_login_class;
                }
            }
            switch ($page) {
                case 'signup':
                    if (!is_user_logged_in()) {
                        if (cp_user_can_register()) {
                            ?>

							<?php 
                            $form_message_class = '';
                            $form_message = '';
                            $student = new Student(0);
                            if (isset($_POST['student-settings-submit'])) {
                                check_admin_referer('student_signup');
                                $min_password_length = apply_filters('coursepress_min_password_length', 6);
                                $student_data = array();
                                $form_errors = 0;
                                do_action('coursepress_before_signup_validation');
                                if ($_POST['username'] != '' && $_POST['first_name'] != '' && $_POST['last_name'] != '' && $_POST['email'] != '' && $_POST['password'] != '' && $_POST['password_confirmation'] != '') {
                                    if (!username_exists($_POST['username'])) {
                                        if (!email_exists($_POST['email'])) {
                                            if ($_POST['password'] == $_POST['password_confirmation']) {
                                                if (!preg_match("#[0-9]+#", $_POST['password']) || !preg_match("#[a-zA-Z]+#", $_POST['password']) || strlen($_POST['password']) < $min_password_length) {
                                                    $form_message = sprintf(__('Your password must be at least %d characters long and have at least one letter and one number in it.', 'cp'), $min_password_length);
                                                    $form_message_class = 'red';
                                                    $form_errors++;
                                                } else {
                                                    if ($_POST['password_confirmation']) {
                                                        $student_data['user_pass'] = $_POST['password'];
                                                    } else {
                                                        $form_message = __("Passwords don't match", 'cp');
                                                        $form_message_class = 'red';
                                                        $form_errors++;
                                                    }
                                                }
                                            } else {
                                                $form_message = __('Passwords don\'t match', 'cp');
                                                $form_message_class = 'red';
                                                $form_errors++;
                                            }
                                            $student_data['role'] = 'student';
                                            $student_data['user_login'] = $_POST['username'];
                                            $student_data['user_email'] = $_POST['email'];
                                            $student_data['first_name'] = $_POST['first_name'];
                                            $student_data['last_name'] = $_POST['last_name'];
                                            if (!is_email($_POST['email'])) {
                                                $form_message = __('E-mail address is not valid.', 'cp');
                                                $form_message_class = 'red';
                                                $form_errors++;
                                            }
                                            if (isset($_POST['tos_agree'])) {
                                                if ($_POST['tos_agree'] == '0') {
                                                    $form_message = __('You must agree to the Terms of Service in order to signup.', 'cp');
                                                    $form_message_class = 'red';
                                                    $form_errors++;
                                                }
                                            }
                                            if ($form_errors == 0) {
                                                if ($student_id = $student->add_student($student_data) !== 0) {
                                                    //$form_message = __( 'Account created successfully! You may now <a href="' . ( get_option( 'use_custom_login_form', 1 ) ? trailingslashit( site_url() . '/' . $this->get_login_slug() ) : wp_login_url() ) . '">log into your account</a>.', 'cp' );
                                                    //$form_message_class = 'regular';
                                                    $email_args['email_type'] = 'student_registration';
                                                    $email_args['student_id'] = $student_id;
                                                    $email_args['student_email'] = $student_data['user_email'];
                                                    $email_args['student_first_name'] = $student_data['first_name'];
                                                    $email_args['student_last_name'] = $student_data['last_name'];
                                                    $email_args['student_username'] = $student_data['user_login'];
                                                    $email_args['student_password'] = $student_data['user_pass'];
                                                    coursepress_send_email($email_args);
                                                    $creds = array();
                                                    $creds['user_login'] = $student_data['user_login'];
                                                    $creds['user_password'] = $student_data['user_pass'];
                                                    $creds['remember'] = true;
                                                    $user = wp_signon($creds, false);
                                                    if (is_wp_error($user)) {
                                                        $form_message = $user->get_error_message();
                                                        $form_message_class = 'red';
                                                    }
                                                    // if( defined('DOING_AJAX') && DOING_AJAX ) { cp_write_log('doing ajax'); }
                                                    if (isset($_POST['course_id']) && is_numeric($_POST['course_id'])) {
                                                        $course = new Course($_POST['course_id']);
                                                        wp_redirect($course->get_permalink());
                                                    } else {
                                                        if (!empty($redirect_url)) {
                                                            wp_redirect(apply_filters('coursepress_redirect_after_signup_redirect_url', $redirect_url));
                                                        } else {
                                                            wp_redirect(apply_filters('coursepress_redirect_after_signup_url', CoursePress::instance()->get_student_dashboard_slug(true)));
                                                        }
                                                    }
                                                    exit;
                                                } else {
                                                    $form_message = __('An error occurred while creating the account. Please check the form and try again.', 'cp');
                                                    $form_message_class = 'red';
                                                }
                                            }
                                        } else {
                                            $form_message = __('Sorry, that email address is already used!', 'cp');
                                            $form_message_class = 'error';
                                        }
                                    } else {
                                        $form_message = __('Username already exists. Please choose another one.', 'cp');
                                        $form_message_class = 'red';
                                    }
                                } else {
                                    $form_message = __('All fields are required.', 'cp');
                                    $form_message_class = 'red';
                                }
                            } else {
                                $form_message = __('All fields are required.', 'cp');
                            }
                            ?>
							<?php 
                            //ob_start();
                            if (!empty($signup_title)) {
                                echo '<' . $signup_tag . '>' . $signup_title . '</' . $signup_tag . '>';
                            }
                            ?>

							<p class="form-info-<?php 
                            echo apply_filters('signup_form_message_class', sanitize_text_field($form_message_class));
                            ?>
"><?php 
                            echo apply_filters('signup_form_message', sanitize_text_field($form_message));
                            ?>
</p>

							<?php 
                            do_action('coursepress_before_signup_form');
                            ?>

							<form id="student-settings" name="student-settings" method="post" class="student-settings">

								<?php 
                            do_action('coursepress_before_all_signup_fields');
                            ?>

								<input type="hidden" name="course_id" value="<?php 
                            esc_attr_e(isset($_GET['course_id']) ? $_GET['course_id'] : ' ');
                            ?>
"/>
								<input type="hidden" name="redirect_url" value="<?php 
                            echo $redirect_url;
                            ?>
"/>

								<label>
									<?php 
                            _e('First Name', 'cp');
                            ?>
:
									<input type="text" name="first_name" value="<?php 
                            echo isset($_POST['first_name']) ? $_POST['first_name'] : '';
                            ?>
"/>
								</label>

								<?php 
                            do_action('coursepress_after_signup_first_name');
                            ?>

								<label>
									<?php 
                            _e('Last Name', 'cp');
                            ?>
:
									<input type="text" name="last_name" value="<?php 
                            echo isset($_POST['last_name']) ? $_POST['last_name'] : '';
                            ?>
"/>
								</label>

								<?php 
                            do_action('coursepress_after_signup_last_name');
                            ?>

								<label>
									<?php 
                            _e('Username', 'cp');
                            ?>
:
									<input type="text" name="username" value="<?php 
                            echo isset($_POST['username']) ? $_POST['username'] : '';
                            ?>
"/>
								</label>

								<?php 
                            do_action('coursepress_after_signup_username');
                            ?>

								<label>
									<?php 
                            _e('E-mail', 'cp');
                            ?>
:
									<input type="text" name="email" value="<?php 
                            echo isset($_POST['email']) ? $_POST['email'] : '';
                            ?>
"/>
								</label>

								<?php 
                            do_action('coursepress_after_signup_email');
                            ?>

								<label>
									<?php 
                            _e('Password', 'cp');
                            ?>
:
									<input type="password" name="password" value=""/>
								</label>

								<?php 
                            do_action('coursepress_after_signup_password');
                            ?>

								<label class="right">
									<?php 
                            _e('Confirm Password', 'cp');
                            ?>
:
									<input type="password" name="password_confirmation" value=""/>
								</label>
								<br clear="both"/><br/>

								<?php 
                            if (shortcode_exists('signup-tos')) {
                                if (get_option('show_tos', 0) == '1') {
                                    ?>
										<label class="full"><?php 
                                    echo do_shortcode('[signup-tos]');
                                    ?>
</label>
									<?php 
                                }
                            }
                            ?>

								<?php 
                            do_action('coursepress_after_all_signup_fields');
                            ?>

								<label class="full">
									<?php 
                            printf(__('Already have an account? %s%s%s!', 'cp'), '<a href="' . $login_url . '">', __('Login to your account', 'cp'), '</a>');
                            ?>
								</label>

								<label class="full-right">
									<input type="submit" name="student-settings-submit" class="apply-button-enrolled" value="<?php 
                            _e('Create an Account', 'cp');
                            ?>
"/>
								</label>

								<?php 
                            do_action('coursepress_after_submit');
                            ?>

								<?php 
                            wp_nonce_field('student_signup');
                            ?>
							</form>
							<div class="clearfix" style="clear: both;"></div>

							<?php 
                            do_action('coursepress_after_signup_form');
                            ?>
							<?php 
                            //$content = ob_get_clean();
                            // Return the html in the buffer.
                            //return $content;
                        } else {
                            _e('Registrations are not allowed.', 'cp');
                        }
                    } else {
                        if (!empty($redirect_url)) {
                            wp_redirect(urldecode($redirect_url));
                        } else {
                            wp_redirect(CoursePress::instance()->get_student_dashboard_slug(true));
                        }
                        exit;
                    }
                    break;
                case 'login':
                    ?>
					<?php 
                    if (!empty($login_title)) {
                        echo '<' . $login_tag . '>' . $login_title . '</' . $login_tag . '>';
                    }
                    ?>
					<p class="form-info-<?php 
                    echo apply_filters('signup_form_message_class', sanitize_text_field($form_message_class));
                    ?>
"><?php 
                    echo apply_filters('signup_form_message', sanitize_text_field($form_message));
                    ?>
</p>
					<?php 
                    do_action('coursepress_before_login_form');
                    ?>
					<form name="loginform" id="student-settings" class="student-settings" method="post">
						<?php 
                    do_action('coursepress_after_start_form_fields');
                    ?>

						<label>
							<?php 
                    _e('Username', 'cp');
                    ?>
:
							<input type="text" name="log" value="<?php 
                    echo isset($_POST['log']) ? $_POST['log'] : '';
                    ?>
"/>
						</label>

						<label>
							<?php 
                    _e('Password', 'cp');
                    ?>
:
							<input type="password" name="pwd" value="<?php 
                    echo isset($_POST['pwd']) ? $_POST['pwd'] : '';
                    ?>
"/>
						</label>

						<?php 
                    do_action('coursepress_form_fields');
                    ?>

						<label class="full">
							<?php 
                    if (cp_user_can_register()) {
                        printf(__('Don\'t have an account? %s%s%s now!', 'cp'), '<a href="' . $signup_url . '">', __('Create an Account', 'cp'), '</a>');
                    }
                    ?>
						</label>

						<label class="half-left">
							<a href="<?php 
                    echo wp_lostpassword_url();
                    ?>
"><?php 
                    _e('Forgot Password?', 'cp');
                    ?>
</a>
						</label>
						<label class="half-right">
							<input type="submit" name="wp-submit" id="wp-submit" class="apply-button-enrolled" value="<?php 
                    _e('Log In', 'cp');
                    ?>
"><br>
						</label>
						<br clear="all"/>

						<input name="redirect_to" value="<?php 
                    echo CoursePress::instance()->get_student_dashboard_slug(true);
                    ?>
" type="hidden">
						<input name="testcookie" value="1" type="hidden">
						<input name="course_signup_login" value="1" type="hidden">
						<?php 
                    do_action('coursepress_before_end_form_fields');
                    ?>
					</form>

					<?php 
                    do_action('coursepress_after_login_form');
                    ?>
					<?php 
                    break;
            }
            $content = ob_get_clean();
            // Return the html in the buffer.
            return $content;
        }
 function virtual_page_template()
 {
     global $post, $wp_query;
     if (isset($post) && $post->post_type == 'virtual_page') {
         $theme_file = locate_template(array('page.php'));
         if ($theme_file != '') {
             include TEMPLATEPATH . "/page.php";
             exit;
         }
     }
     if (cp_use_woo() && cp_redirect_woo_to_course()) {
         if (isset($post) && $post->post_type == 'product') {
             if (isset($post->post_parent)) {
                 //parent course
                 if ($post->post_parent !== 0 && get_post_type($post->post_parent) == 'course') {
                     $course = new Course($post->post_parent);
                     wp_redirect($course->get_permalink());
                     exit;
                 }
             }
         }
     } else {
         if (isset($post) && $post->post_type == 'product' && $wp_query->is_page) {
             if (isset($post->post_parent)) {
                 //parent course
                 if ($post->post_parent !== 0 && get_post_type($post->post_parent) == 'course') {
                     $course = new Course($post->post_parent);
                     wp_redirect($course->get_permalink());
                     exit;
                 }
             }
         }
     }
 }
    function widget($args, $instance)
    {
        extract($args, EXTR_SKIP);
        echo $before_widget;
        $course_id = $instance['course'];
        $course = new Course($course_id);
        $selected_type = isset($instance['type']) ? $instance['type'] : 'image';
        $selected_priority = isset($instance['priority']) ? $instance['priority'] : 'image';
        $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
        if (!empty($title)) {
            echo $before_title . $title . $after_title;
        }
        ?>
		<div class=fcp_featured_widget cp_featured_widget-course-<?php 
        echo $course_id;
        ?>
">
	        <h3 class="cp_featured_widget_title"><?php 
        echo esc_html($course->details->post_title);
        ?>
</h3>
	        <?php 
        echo do_shortcode('[course_media type="' . $selected_type . '" priority="' . $selected_priority . '" course_id="' . $course_id . '"]');
        ?>
	        <div class="cp_featured_widget_course_summary">
	        <?php 
        echo do_shortcode('[course_summary course_id="' . $course_id . '" length="30"]');
        ?>
	        </div>

	        <div class="cp_featured_widget_course_link">
				<button data-link="<?php 
        echo esc_url($course->get_permalink($course_id));
        ?>
"><?php 
        echo esc_html($instance['button_title']);
        ?>
</button>
	        </div>
		</div>
        <?php 
        echo $after_widget;
    }
                        printf(__('Congratulations, you have successfully enrolled in "%s" course! Check your %s for more info.', 'cp'), '<strong>' . $course->details->post_title . '</strong>', '<a href="' . $this->get_student_dashboard_slug(true) . '">' . __('Dashboard', 'cp') . '</a>');
                    } else {
                        _e('Something went wrong during the enrollment process. Please try again later.', 'cp');
                    }
                } else {
                    if ($course->is_user_purchased_course($course->details->marketpress_product, get_current_user_ID())) {
                        //Enroll student in
                        if ($student->enroll_in_course($course_id)) {
                            printf(__('Congratulations, you have successfully enrolled in "%s" course! Check your %s for more info.', 'cp'), '<strong>' . $course->details->post_title . '</strong>', '<a href="' . $this->get_student_dashboard_slug(true) . '">' . __('Dashboard', 'cp') . '</a>');
                        } else {
                            _e('Something went wrong during the enrollment process. Please try again later.', 'cp');
                        }
                    } else {
                        $course->show_purchase_form($course->details->marketpress_product);
                    }
                }
            } else {
                printf(__('Passcode is not valid. Please %s and try again.', 'cp'), '<a href="' . esc_url($course->get_permalink()) . '">' . __('go back', 'cp') . '</a>');
            }
        } else {
            // if( defined('DOING_AJAX') && DOING_AJAX ) { cp_write_log('doing ajax'); }
            // _e( 'You have already enrolled in the course.', 'cp' ); //can't enroll more than once to the same course at the time
            wp_redirect(trailingslashit($course->get_permalink()) . 'units');
            exit;
        }
    } else {
        _e('Please select a course first you want to enroll in.', 'cp');
    }
} else {
    _e('You must be logged in in order to complete the action', 'cp');
}
function coursepress_send_email($email_args = array())
{
    if ($email_args['email_type'] == 'student_registration') {
        global $course_slug;
        $email_address = $email_args['student_email'];
        $subject = coursepress_get_registration_email_subject();
        $courses_address = trailingslashit(home_url()) . trailingslashit($course_slug);
        $tags = array('STUDENT_FIRST_NAME', 'STUDENT_LAST_NAME', 'STUDENT_USERNAME', 'STUDENT_PASSWORD', 'BLOG_NAME', 'LOGIN_ADDRESS', 'COURSES_ADDRESS', 'WEBSITE_ADDRESS');
        $tags_replaces = array($email_args['student_first_name'], $email_args['student_last_name'], $email_args['student_username'], $email_args['student_password'], get_bloginfo(), cp_student_login_address(), $courses_address, home_url());
        $message = coursepress_get_registration_content_email();
        $message = str_replace($tags, $tags_replaces, $message);
        add_filter('wp_mail_from', 'my_registration_from_function');
        if (!function_exists('my_registration_from_function')) {
            function my_registration_from_function($email)
            {
                return coursepress_get_registration_from_email();
            }
        }
        add_filter('wp_mail_from_name', 'my_registration_from_name_function');
        if (!function_exists('my_registration_from_name_function')) {
            function my_registration_from_name_function($name)
            {
                return coursepress_get_registration_from_name();
            }
        }
    }
    if ($email_args['email_type'] == 'enrollment_confirmation') {
        global $course_slug;
        $email_address = $email_args['student_email'];
        $dashboard_address = $email_args['dashboard_address'];
        $subject = coursepress_get_enrollment_email_subject();
        $courses_address = trailingslashit(home_url()) . trailingslashit($course_slug);
        $course = new Course($email_args['course_id']);
        $tags = array('STUDENT_FIRST_NAME', 'STUDENT_LAST_NAME', 'BLOG_NAME', 'LOGIN_ADDRESS', 'COURSES_ADDRESS', 'WEBSITE_ADDRESS', 'COURSE_ADDRESS', 'COURSE_TITLE', 'STUDENT_DASHBOARD');
        $tags_replaces = array($email_args['student_first_name'], $email_args['student_last_name'], get_bloginfo(), cp_student_login_address(), $courses_address, home_url(), $course->get_permalink(), $course->details->post_title, $email_args['dashboard_address']);
        $message = coursepress_get_enrollment_content_email();
        $message = str_replace($tags, $tags_replaces, $message);
        add_filter('wp_mail_from', 'my_enrollment_from_function');
        if (!function_exists('my_enrollment_from_function')) {
            function my_enrollment_from_function($email)
            {
                return coursepress_get_enrollment_from_email();
            }
        }
        add_filter('wp_mail_from_name', 'my_enrollment_from_name_function');
        if (!function_exists('my_enrollment_from_name_function')) {
            function my_enrollment_from_name_function($name)
            {
                return coursepress_get_enrollment_from_name();
            }
        }
    }
    if ($email_args['email_type'] == 'student_invitation') {
        global $course_slug;
        $email_address = $email_args['student_email'];
        if (isset($email_args['course_id'])) {
            $course = new Course($email_args['course_id']);
        }
        $tags = array('STUDENT_FIRST_NAME', 'STUDENT_LAST_NAME', 'COURSE_NAME', 'COURSE_EXCERPT', 'COURSE_ADDRESS', 'WEBSITE_ADDRESS', 'PASSCODE');
        $tags_replaces = array($email_args['student_first_name'], $email_args['student_last_name'], $course->details->post_title, $course->details->post_excerpt, $course->get_permalink(), home_url(), $course->details->passcode);
        if ($email_args['enroll_type'] == 'passcode') {
            $message = coursepress_get_invitation_content_passcode_email();
            $subject = coursepress_get_invitation_passcode_email_subject();
        } else {
            $message = coursepress_get_invitation_content_email();
            $subject = coursepress_get_invitation_email_subject();
        }
        $message = str_replace($tags, $tags_replaces, $message);
        add_filter('wp_mail_from', 'my_passcode_from_function');
        if (!function_exists('my_passcode_from_function')) {
            function my_passcode_from_function($email)
            {
                return coursepress_get_invitation_passcode_from_email();
            }
        }
        add_filter('wp_mail_from_name', 'my_passcode_from_name_function');
        if (!function_exists('my_passcode_from_name_function')) {
            function my_passcode_from_name_function($name)
            {
                return coursepress_get_invitation_passcode_from_name();
            }
        }
    }
    if ('instructor_invitation' == $email_args['email_type']) {
        global $course_slug;
        $course = '';
        $course_summary = '';
        $course_name = '';
        $courses_address = trailingslashit(home_url()) . trailingslashit($course_slug);
        $bugfix = false;
        if (isset($email_args['course_id'])) {
            $course = new Course($email_args['course_id']);
            $course_name = $course->details->post_title;
            $course_summary = $course->details->post_excerpt;
            // For unpublished courses.
            $permalink = '';
            if (in_array($course->details->post_status, array('draft', 'pending', 'auto-draft'))) {
                $permalink = CoursePress::instance()->get_course_slug(true) . '/' . $course->details->post_name . '/';
            } else {
                $permalink = get_permalink($email_args['course_id']);
            }
            $course_address = $permalink;
        }
        $confirm_link = $course_address . '?action=course_invite&course_id=' . $email_args['course_id'] . '&c=' . $email_args['invite_code'] . '&h=' . $email_args['invite_hash'];
        $email_address = $email_args['instructor_email'];
        $subject = cp_get_instructor_invitation_email_subject();
        $tags = array('INSTRUCTOR_FIRST_NAME', 'INSTRUCTOR_LAST_NAME', 'INSTRUCTOR_EMAIL', 'CONFIRMATION_LINK', 'COURSE_NAME', 'COURSE_EXCERPT', 'COURSE_ADDRESS', 'WEBSITE_ADDRESS', 'WEBSITE_NAME');
        $tags_replaces = array($email_args['first_name'], $email_args['last_name'], $email_address, $confirm_link, $course_name, $course_summary, $course_address, home_url(), get_bloginfo());
        $message = cp_get_instructor_invitation_email();
        $message = str_replace($tags, $tags_replaces, $message);
        add_filter('wp_mail_from', 'my_instructor_invitation_from_function');
        if (!function_exists('my_instructor_invitation_from_function')) {
            function my_instructor_invitation_from_function($email)
            {
                return coursepress_get_instructor_invitation_from_email();
            }
        }
        add_filter('wp_mail_from_name', 'my_instructor_invitation_from_name_function');
        if (!function_exists('my_instructor_invitation_from_name_function')) {
            function my_instructor_invitation_from_name_function($name)
            {
                return coursepress_get_instructor_invitation_from_name();
            }
        }
    }
    add_filter('wp_mail_content_type', 'cp_email_set_content_type');
    if (!function_exists('cp_email_set_content_type')) {
        function cp_email_set_content_type($content_type)
        {
            return 'text/html';
        }
    }
    add_filter('wp_mail_charset', 'cp_set_charset');
    if (!function_exists('cp_set_charset')) {
        function cp_set_charset($charset)
        {
            return get_option('blog_charset');
        }
    }
    return wp_mail($email_address, stripslashes($subject), stripslashes(nl2br($message)));
}