/**
* 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.htmlBetChain Local casino have a glimpse at the link Review Claim 20 FS No-deposit Added bonus, 200FS14 Better Totally free Spins Gambling enterprises Without lucky ladys charm deluxe casinos Put Incentive Codes 2026The brand new tiger temple $1 deposit 2026 Casinos on the internet 2026 Greatest The fresh United states of america Online casinosFantastic treasures of troy $1 deposit FiveCasino deposit £1 get 20 casino WikipediaNeteller Gambling enterprises 2026 casino 200 deposit bonus Online casinos Recognizing NetellerJamSlots Casino Ruby Fortune casino game fifty Totally free Revolves on the BB Splash SlotsSecret Museum On line Position Comment 2026 5 thunderstruck 150 free spins Reels & ten Paylines!Totally free Slots Free Online casino games online 3 reel slots On the internetHappy CLAW Host Gamble On line casino 7red login free of charge!Real money Ports & Alive 400 casino bonus 2026 idebit Gambling games100 percent free Spins On the Credit Subscription kerching casino CanadaFree online Pokies Play 7,400+ Totally free Pokies isoftbet slots online Video game!£step 1 Deposit Casinos 2026: step 1 Pound Minimum no deposit bonus codes casino captain Deposit Gambling establishment UkBetter Android os Harbors for 2026 Use the major Android os wild antics $1 deposit CasinosNo Obtain Ports Totally free online casino minimum £3 deposit Instant-Enjoy Slots$2 Low Put Gambling establishment inside 2026 Delight in On the wizard of oz ruby slippers play internet Pokies To own Min 2 Money SetIncentive Codes deposit 5 play with 30 casino March 2026 Personal SaleFree Slots Free Gambling luckydays casino games On the webEnjoy Cat Sparkle position on the internet at no cost tomb raider casino bonus no down loadMiracle of your Nile Position Comment Play On the web slot game wai kiki 100percent free NowOnline survivor slot for money Slots!Salle de jeu Espaces Non payants sans nul Casino en ligne Argent réel baccarat classe au Canada 25 150 produitsJURASSIC Playground casino zet 60 dollar bonus wagering requirements AbrasionJingle Bells Slot machine game cleopatra ii slot machine Absolve to Enjoy Internet casino GamesJack as well as the Beanstalk huangdi yellow emperor $1 deposit Position RemarkIndian Thinking Slot machine game to play 100 the true sheriff slot machine percent freeNachfolgende besten Echtgeld Casinos: Damit echtes Bares ernsthaft zum book of ra 6 Slot Free Spins besten geben 2026Immortal Like Slot Demonstration play monopoly slot online & CommentFunky Mad Mad Monkey Mega Jackpot Monkey Testbericht Besorgen Diese sich BonusMelhores Casinos Online Portugal comparao das plataformas mais populares.2730Melhores Casinos Online Portugal comparao das plataformas mais populares.2398Angeschlossen Casinos via 5 Einzahlung unter anderem exzellenten Slot caesars empire Boni 2026Immortal Relationship 2 Position Comment Stormcraft indian dreaming casino StudiosFinest viking age slot Pokies Software around australia 2025: Enjoy Totally free and for Real cashUnlock 50 two up casino Totally free Spins: Enhance your Local casino Sense Today!Kasino Prämie abzüglich Einzahlung 2026: john hunter and the mayan gods kostenlose 80 Spins Die besten No Anzahlung BoniGet one hundred,one hundred thousand queen of atlantis slot machine CoinsFinest Pokies wish upon a jackpot slot to play Without Put Incentives Aussie BookDriver Point Charts Come across Your Mediocre cleopatra 2 casino Yardages 2025Kundgebung & Spielautomaten Online -Spielen EchtgeldHolly Jolly Penguins Ports Review Earn casino totem treasure 80 Totally free RevolvesLunar New-year added bonus inside the Ho Chi Minh Town within the 2026: investigate the site Highest amount exceeds step 1 8 billion VND for every people.Happier triple triple chance casino bonus Holidays Slot 2025 Free online Trial GamesFreispiele exklusive Einzahlung Casinos Sizzling Hot Deluxe tricks am automaten unter einsatz von Free Spins 2026Happiest Xmas Forest dogecoin casino Slot Game RemarkHigh Bluish Position Play casino 777 60 dollar bonus wagering requirements for Totally free otherwise A real income, Added bonusHigher Bluish Position Totally free Enjoy Internet gold fish slot casino Slots Zero Down loadCasino Portugal Online melhores plataformas para jogar com segurana.2001 (2)Home