/** * Adds course member * * @access public * @param int $ID * @param bool $private * @return void */ public static function addUser($ID, $user, $private = false) { self::refresh($ID); $redirect = get_permalink($ID); if ($user != 0 || self::$data['status'] == 'premium' && self::$data['product'] != 0) { if (!self::isMember($user)) { if ($private || self::$data['status'] == 'free' || self::$data['status'] == 'premium' && self::$data['product'] == 0) { ThemexCore::addUserRelation($user, $ID, 'course', current_time('timestamp')); self::$data['users'][] = $user; $number = count(self::$data['users']); ThemexCore::updatePostMeta($ID, 'course_popularity', $number); $message = ThemexCore::getOption('email_course'); if (!empty($message)) { $data = get_userdata($user); $keywords = array('username' => $data->user_login, 'title' => get_the_title($ID), 'link' => $redirect); themex_mail($data->user_email, __('Course Membership', 'academy'), themex_keywords($message, $keywords)); } if (!$private) { wp_redirect($redirect); exit; } } else { if (self::$data['status'] == 'premium') { ThemexWoo::addProduct(self::$data['product']); } } } else { if (!$private) { wp_redirect($redirect); exit; } } } }
/** * Logins Facebook user * * @access public * @return void */ public static function loginUser() { if (isset($_GET['facebook_login']) && !is_user_logged_in() && isset($_COOKIE['fbsr_' . ThemexCore::getOption('facebook_id')])) { $cookie = self::decodeCookie(); if (isset($cookie['code'])) { $profile = self::getProfile($cookie['user_id'], array('fields' => 'first_name,last_name,email', 'code' => $cookie['code'], 'sslverify' => 0)); if (isset($profile['email'])) { $user = get_user_by('email', sanitize_email($profile['email'])); if ($user !== false) { $ID = $user->ID; wp_set_auth_cookie($user->ID, true); } else { if (isset($profile['first_name'])) { $profile['username'] = $profile['first_name']; } else { if (isset($profile['last_name'])) { $profile['username'] = $profile['last_name']; } } $profile['username'] = sanitize_user($profile['username']); $profile['password'] = wp_generate_password(8); while (username_exists($profile['username'])) { $profile['username'] .= rand(0, 9); } $ID = wp_create_user($profile['username'], $profile['password'], $profile['email']); if (!is_wp_error($ID)) { wp_new_user_notification($ID); add_user_meta($ID, 'facebook_id', $profile['id'], true); self::updateImage($profile['id'], $ID); if (isset($profile['first_name'])) { update_user_meta($ID, 'first_name', $profile['first_name']); } if (isset($profile['last_name'])) { update_user_meta($ID, 'last_name', $profile['last_name']); } $subject = __('Registration Complete', 'academy'); $message = ThemexCore::getOption('email_registration', 'Hi, %username%! Welcome to ' . get_bloginfo('name') . '. '); $keywords = array('username' => $profile['username'], 'password' => $profile['password'], 'link' => home_url()); wp_set_auth_cookie($ID, true); themex_mail($profile['email'], $subject, themex_keywords($message, $keywords)); } else { self::logoutUser(); } } //redirect here if (isset($_GET['user_redirect']) && !empty($_GET['user_redirect'])) { $redirect = ThemexCore::getURL('redirect', intval($_GET['user_redirect'])); } else { $redirect = get_author_posts_url($ID); } wp_redirect($redirect); exit; } } wp_redirect(SITE_URL); exit; } }
/** * Validates lesson question * * @access public * @param array $comment * @return array */ public static function validateQuestion($comment) { if (get_post_type() == 'lesson') { if ($comment['comment_parent'] == 0 && (!isset($_POST['title']) || empty($_POST['title']))) { wp_die('<strong>' . __('ERROR', 'academy') . '</strong>: ' . __('please type a question.', 'academy')); } $message = ThemexCore::getOption('email_question'); if ($comment['comment_parent'] !== 0 && !empty($message)) { $question = get_comment($comment['comment_parent'], ARRAY_A); $replies = get_comments(array('parent' => $comment['comment_parent'])); $emails = wp_list_pluck($replies, 'comment_author_email'); if (!empty($question)) { $emails[] = $question['comment_author_email']; } $emails = array_unique(array_filter($emails)); foreach ($emails as $email) { if ($email != $comment['comment_author_email']) { $data = get_user_by('email', $email); if ($data !== false) { $keywords = array('username' => $data->user_login, 'title' => get_comment_meta($comment['comment_parent'], 'title', true), 'link' => get_comment_link($comment['comment_parent'])); themex_mail($emails, __('Question Answered', 'academy'), themex_keywords($message, $keywords)); } } } } } return $comment; }
/** * Resets password * * @access public * @param array $data * @return void */ public static function resetPassword($data) { global $wpdb, $wp_hasher; if (email_exists(sanitize_email($data['user_email']))) { $user = get_user_by('email', sanitize_email($data['user_email'])); do_action('lostpassword_post'); $login = $user->user_login; $email = $user->user_email; do_action('retrieve_password', $login); $allow = apply_filters('allow_password_reset', true, $user->ID); if (!$allow || is_wp_error($allow)) { ThemexInterface::$messages[] = __('Password recovery not allowed', 'academy'); } else { $key = wp_generate_password(20, false); do_action('retrieve_password_key', $login, $key); if (empty($wp_hasher)) { require_once ABSPATH . 'wp-includes/class-phpass.php'; $wp_hasher = new PasswordHash(8, true); } $hashed = $wp_hasher->HashPassword($key); $wpdb->update($wpdb->users, array('user_activation_key' => $hashed), array('user_login' => $login)); $link = network_site_url('wp-login.php?action=rp&key=' . $key . '&login='******'login'); $message = ThemexCore::getOption('email_password', 'Hi, %username%! Click this link to reset your password %link%'); $keywords = array('username' => $user->user_login, 'link' => $link); if (themex_mail($email, __('Password Recovery', 'academy'), themex_keywords($message, $keywords))) { ThemexInterface::$messages[] = __('Password reset link is sent', 'academy'); } else { ThemexInterface::$messages[] = __('Error sending email', 'academy'); } } } else { ThemexInterface::$messages[] = __('Invalid email address', 'academy'); } ThemexInterface::renderMessages(); die; }
/** * Submits user message * * @access public * @param int $ID * @param array $data * @return void */ public static function submitMessage($ID, $data) { $user = intval(themex_value('user_id', $data)); if (!empty($user)) { $message = sanitize_text_field(themex_value('message', $data)); if (empty($message)) { ThemexInterface::$messages[] = '"' . __('Message', 'makery') . '" ' . __('field is required', 'makery'); } if (empty(ThemexInterface::$messages)) { $subject = __('New Message', 'makery'); $content = ThemexCore::getOption('email_message', 'Sender: %user%<br />Message: %message%'); $receiver = get_userdata($user); $sender = get_userdata($ID); $keywords = array('user' => '<a href="' . get_author_posts_url($sender->ID) . '">' . $sender->user_login . '</a>', 'message' => wpautop($message)); $content = themex_keywords($content, $keywords); themex_mail($receiver->user_email, $subject, $content, $sender->user_email); ThemexInterface::$messages[] = __('Message has been successfully sent', 'makery'); ThemexInterface::renderMessages(true); } else { ThemexInterface::renderMessages(); } } die; }
/** * Adds order * * @access public * @param int $ID * @return void */ public static function addOrder($ID) { $order = wc_get_order($ID); $products = $order->get_items(); //set author if (!empty($products)) { $product = reset($products); $post = get_post($product['product_id']); //set affiliate $referral = get_current_user_id(); $affiliate = self::getAffiliate(); if (!empty($affiliate) && $affiliate != $referral) { ThemexCore::updatePostMeta($ID, 'affiliate', $affiliate); self::removeAffiliate(); //send email $content = ThemexCore::getOption('email_order_referral'); if (!empty($content)) { $user = get_userdata($affiliate); if ($user !== false) { $subject = __('New Referral', 'makery'); $keywords = array('username' => $user->user_login, 'order' => '<a href="' . ThemexCore::getURL('profile-referrals') . '">' . $order->get_order_number() . '</a>'); $content = themex_keywords($content, $keywords); themex_mail($user->user_email, $subject, $content); } } } if (!empty($post)) { wp_update_post(array('ID' => $ID, 'post_author' => $post->post_author)); //send email $content = ThemexCore::getOption('email_order_received'); if (!empty($content)) { $user = get_userdata($post->post_author); $subject = __('New Order', 'makery'); $keywords = array('username' => $user->user_login, 'order' => '<a href="' . ThemexCore::getURL('shop-order', $order->id) . '">' . $order->get_order_number() . '</a>'); $content = themex_keywords($content, $keywords); themex_mail($user->user_email, $subject, $content); } } } }
/** * Submits shop report * * @access public * @param array $data * @return void */ public static function submitReport($data) { $shop = intval(themex_value('shop_id', $data)); if (!empty($shop)) { $reason = sanitize_text_field(themex_value('reason', $data)); if (empty($reason)) { ThemexInterface::$messages[] = '"' . __('Reason', 'makery') . '" ' . __('field is required', 'makery'); } if (empty(ThemexInterface::$messages)) { $subject = __('Shop Report', 'makery'); $content = ThemexCore::getOption('email_shop_report', 'Sender: %user%<br />Shop: %shop%<br />Reason: %reason%'); $user = get_userdata(get_current_user_id()); $keywords = array('user' => '<a href="' . get_author_posts_url($user->ID) . '">' . $user->user_login . '</a>', 'shop' => '<a href="' . get_permalink($shop) . '">' . get_the_title($shop) . '</a>', 'reason' => wpautop($reason)); $content = themex_keywords($content, $keywords); themex_mail(get_option('admin_email'), $subject, $content, $user->user_email); ThemexInterface::$messages[] = __('Report has been successfully sent', 'makery'); ThemexInterface::renderMessages(true); } else { ThemexInterface::renderMessages(); } } die; }
/** * Submits form data * * @access public * @return void */ public static function submitData() { self::refresh(); parse_str($_POST['data'], $data); if (isset($data['slug']) && self::isActive($data['slug'])) { if (isset(self::$data[$data['slug']]['captcha'])) { session_start(); $posted_code = md5($data['captcha']); $session_code = $_SESSION['captcha']; if ($session_code != $posted_code) { ThemexInterface::$messages[] = __('The verification code is incorrect', 'academy'); } } foreach (self::$data[$data['slug']]['fields'] as $field) { $ID = themex_sanitize_key($field['name']); $field['name'] = themex_get_string($ID, 'name', $field['name']); if ((!isset($data[$ID]) || trim($data[$ID]) == '') && !isset($field['optional']) && $field['type'] != 'checkbox') { ThemexInterface::$messages[] = '"' . $field['name'] . '" ' . __('field is required', 'academy'); } else { if ($field['type'] == 'number' && !is_numeric($data[$ID])) { ThemexInterface::$messages[] = '"' . $field['name'] . '" ' . __('field can only contain numbers', 'academy'); } if ($field['type'] == 'email' && !is_email($data[$ID])) { ThemexInterface::$messages[] = __('You have entered an invalid email address', 'academy'); } } } if (!empty(ThemexInterface::$messages)) { ThemexInterface::renderMessages(); } else { $email = get_option('admin_email'); $subject = __('Contact', 'academy'); $message = ''; foreach (self::$data[$data['slug']]['fields'] as $field) { $ID = themex_sanitize_key($field['name']); $field['name'] = themex_get_string($ID, 'name', $field['name']); if ($field['type'] == 'select') { $field['options'] = themex_get_string($ID, 'options', $field['options']); $items = explode(',', $field['options']); if (isset($items[$data[$ID] - 1])) { $data[$ID] = $items[$data[$ID] - 1]; } else { $data[$ID] = '–'; } } else { if ($field['type'] == 'textarea') { $data[$ID] = nl2br($data[$ID]); } } $message .= '<strong>' . $field['name'] . '</strong>: ' . $data[$ID] . '<br />'; } if (themex_mail($email, $subject, $message) && isset(self::$data[$data['slug']]['message'])) { $message = themex_get_string($data['slug'], 'message', self::$data[$data['slug']]['message']); ThemexInterface::$messages[] = $message; } ThemexInterface::renderMessages(true); } } die; }