/**
* EnrollUserToCourse.
* php version 5.6
*
* @category EnrollUserToCourse
* @package SureTriggers
* @author BSF
* @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3
* @link https://www.brainstormforce.com/
* @since 1.0.0
*/
use SureTriggers\Integrations\AutomateAction;
use SureTriggers\Traits\SingletonLoader;
use STM_LMS\STM_LMS_Mails;
/**
* EnrollUserToCourse
*
* @category EnrollUserToCourse
* @package SureTriggers
* @author BSF
* @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3
* @link https://www.brainstormforce.com/
* @since 1.0.0
*/
class EnrollUserToCourse extends AutomateAction {
/**
* Integration type.
*
* @var string
*/
public $integration = 'MasterStudyLms';
/**
* Action name.
*
* @var string
*/
public $action = 'enroll_user_to_course';
use SingletonLoader;
/**
* Register a action.
*
* @param array $actions actions.
* @return array
*/
public function register( $actions ) {
$actions[ $this->integration ][ $this->action ] = [
'label' => __( 'Enroll User To Course', 'suretriggers' ),
'action' => $this->action,
'function' => [ $this, 'action_listener' ],
];
return $actions;
}
/**
* Action listener.
*
* @param int $user_id user_id.
* @param int $automation_id automation_id.
* @param array $fields fields.
* @param array $selected_options selectedOptions.
* @psalm-suppress UndefinedMethod
* @throws Exception Exception.
*
* @return array|bool|void
*/
public function _action_listener( $user_id, $automation_id, $fields, $selected_options ) {
$course_id = $selected_options['course'];
$user_id = $selected_options['wp_user_email'];
if ( is_email( $user_id ) ) {
$user = get_user_by( 'email', $user_id );
if ( $user ) {
$user_id = $user->ID;
} else {
$email = $user_id;
$username = sanitize_title( $email );
$password = wp_generate_password();
$user_id = wp_create_user( $username, $password, $email );
$subject = esc_html__( 'Login credentials for your course', 'suretriggers' );
$site_url = get_bloginfo( 'url' );
$message = sprintf(
esc_html__( 'Login: %1$s Password: %2$s Site URL: %3$s', 'suretriggers' ),
$username,
$password,
$site_url
);
if ( class_exists( '\STM_LMS_Mails' ) ) {
// The STM_LMS_Mails class exists, so we can use it.
\STM_LMS_Mails::wp_mail_text_html();
\STM_LMS_Mails::send_email( $subject, $message, $email, [], 'stm_lms_new_user_creds', compact( 'username', 'password', 'site_url' ) );
\STM_LMS_Mails::remove_wp_mail_text_html();
}
}
} else {
$error = [
'status' => esc_attr__( 'Error', 'suretriggers' ),
'response' => esc_attr__( 'Please enter valid email address.', 'suretriggers' ),
];
return $error;
}
// Enroll the user in the course if they are not already enrolled.
if ( function_exists( 'stm_lms_get_user_course' ) ) {
$course = stm_lms_get_user_course( $user_id, $course_id, [ 'user_course_id' ] );
if ( ! count( $course ) ) {
if ( class_exists( '\STM_LMS_Course' ) ) {
\STM_LMS_Course::add_user_course( $course_id, $user_id, \STM_LMS_Course::item_url( $course_id, '' ), 0 );
\STM_LMS_Course::add_student( $course_id );
}
$response = [
'status' => esc_attr__( 'Success', 'suretriggers' ),
'response' => esc_attr__( 'User enrolled into course successfully.', 'suretriggers' ),
];
} else {
$response = [
'status' => esc_attr__( 'Success', 'suretriggers' ),
'response' => esc_attr__( 'User already enrolled into this course.', 'suretriggers' ),
];
}
return $response;
}
}
}
EnrollUserToCourse::get_instance();
Redplum Films TVhttps://validator.w3.org/feed/docs/rss2.htmlHomeОфициальный Сайт Вход на Рабочее Зеркало Vavada 2026.2672Casino quelque peu 2023 deux sites avec salle de jeu quelque peu sphinx Casino mobile fiables pour 10 000+ jeuxBest Real money Ports United states 2026 Online slots at the Best CasinosNajpozytywniejsze Kasyna Online w naszym krajuOnline slots for real CurrencyLender transfers, Paysafecard and you may Fruit Pay also have an apparent exposureKasyno przez internet na prawdziwe finanse I Automaty do uciechy zbytnio gotówkęPorts Online games for real Currency Best ten Casinos April 2026Najpozytywniejsze Kasyna na Oryginalne Pieniążki w polsce 2026Najistotniejsze Kasyna Android na terytorium polski Ewidencja 2026Best Us No deposit Bonus Casinos 2026: Find No deposit Also offers ListRuby Luck Casino Bonus Codes: No-Password Also offers NowNajistotniejsze Kasyna Na iPhone na terytorium polski w całej 2026LuckyLand Ports Comment 2026: Casino Reviews & Truthful OpinionsNajpozytywniejsze polskie kasyna android Top aplikacje kasynowe 2026Legalne kasyno sieciowy 2026 z KNP: Licencje, wykaz oraz wytyczne rozrywkiRealPrize Promo Password Scores Up to 625K GC & 125 Free South carolinaurzędowy przewodnik, zastosowanie, recenzjeBest No deposit Ports 2026 Best No deposit Ports Also offersOficjalne lokalne kasyno sieciowy spośród bonusem do odwiedzenia dziesięć,000 złotychNo deposit Bonus Codes Private Free Also offers in the 2026Recenzje jak i również podręczniki dotyczące naszych kasyn netowych Najistotniejsze strony przy 2026Heart Casino Coupons February 2026 Latest Free SpinsNajkorzystniejsze Krajowe Kasyno Sieciowy Opinie: Poglądy i Marki Rodzimych Kasyn po 2026Free Spins No deposit 2026 ️step 1,000+ Bonus SpinsNajlepsze kasyno przez internet Polska 2026 Zestawienia & opinieBetMGM Casino No deposit Bonus Password 2026 $twenty five that have 1x WageringNajlepsze Polskie Kasyna Internetowego ᐈ Kwiecień 2026 ᐈ Kasyno AnalyzerLatest Online casino Bonus Codes: Latest PromotionsNajkorzystniejsze Kasyna Sieciowy w naszym kraju w całej 2026 3114Best Ports in america Best Online slots and you can Sites to have 2025Legalne Kasyna Internetowego w polsce Lista 2026Free Ports Online Play 20,000+ Demo Slot GamePerhaps not consenting otherwise withdrawing consent, will get negatively affect particular possess and proceduresKrajowe Kasyno Online ️ Najlepsze Kasyna Online 2026Uk Slot Sites 2026 Best Online slots & Biggest JackpotsOryginalne Polskie Kasyna 2026 Ranking Kasyn od czasu EkspertówInterest Required! CloudflareDarmowe spiny z brakiem depozytu najpozytywniejsze ogłoszenia na polskim rynkuNajpozytywniejsze przedsiębiorstwa w kategorii Casino w Trustpilot pięć z 16Online casino Play with 250% Bonus To the200 Zł Premia Z brakiem Depozytu Kasyno SieciowyWe’re going to now glance at the associated commission tips you might fool around with at each and every on-line casinoPrivate Bonuses Updated Every dayZarzuty dla Buddy Kiedy legalna loteria może okazać się zakazana? Adwokat objaśniaOur functions could have been appeared to the big platforms like ESPN, Forbes, GoogleBonusy Kasynowe 2026 Najdogodniejszy Bonus W Kasyno Na terytorium polskiIncluding the most common incentive the net casino no-deposit extraNajkorzystniejsze kasyno online na terytorium polski Kasyna online 2026