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 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)));
}