/**
* 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.htmlInternationella online casinon fr svenskar.65961Win Giri Trkiyede Online Casino.6699 (2)Online Casino Utan Svensk Licens – Casino utan Spelpaus.20874 (2)HomeFree Revolves без депозит 2026Styled мобилно приложение trinocasino Range Games Machines, Играйте безплатноWizard from Ounce: Way to the brand new Emerald Town 100 percent free Trial 2026Free Casino games One Shell out A real income Without PutFinest Web based casinos Us 2026 Best-Ranked & Trusted A real income Internet sitesFortunate Larrys Lobstermania 2 تم التحقق من أنها ألعاب تجريبية مجانية بنسبة 100 بالمائة على الويبNuts Orient Position Opinion & The best places to Gamble On line MicrogamingTop ten Internet casino Real cash Sites February 2026Visa Online casinos One to Service Visa since the Detachment StrategyGambling Calculators#1 RTP Checker to possess Slots & Gambling enterprises Real-DateDual Twist Slot Opinion 2026 Gamble 100 percent free TrialGamble 19,300+ 100 percent free Slot Video game Zero InstallMultiple Diamond Slot Free Play On-line casino Ports Zero Down loadCasino slot games WikipediaGamble Alaskan Angling Harbors 2026 Remark To have AustraliansTop Bitcoin Gambling enterprises: Better BTC Crypto Betting Internet sites to possess 2025 Biggest Guide Spending reports400% Local casino Incentives to possess U S. People eight hundred% Gambling enterprise IncentivesTop ten Finest Online casinos right now 2026Tomb Raider Position by Microgaming » Laura Croft is hereHollywood Collectibles Tunica, MississippiYahtzee 31 totally free spins no deposit necessary WikipediaSense Quality Slots Having Thor55 The newest No-deposit Bonus Rules To have Mar 2026 Updated Daily300% Extra First Put Gambling establishment Offers : Maneki Pro SelectionsGreatest Free Spins No deposit Now offers 2026 step one,000+ Spins!AC_DC Thunderstruck Certified MoviesNuts Panda Position Free Enjoy and Comment 94 36 % RTPCasino slot games RemarkTop 10 Internet casino A real income Web sites February 2026Finest $5 Minimal Put Casinos Us 2026Finest Online video Ports 2026Totally free Spins & Award MultipliersTroll Seekers 2 Position Comment 2025 Play for Free Right hereThunderstruck II position Totally free Gamble On the web Microgaming HomeDebunking Myths About Transfer on Death Deeds and Estate PlanningLegal Tools for Smooth Property Transfers After DeathThe Path to Ensure a Smooth Transfer of Boat Ownership: A Step-by-Step GuideWhat Makes Articles of Incorporation Key to Your Business StructureCut Stack 150: Un Alleato Potente per il Tuo AllenamentoGuide complet du casino en ligne : tout ce que vous devez savoir en 2026Guide complet du casino en ligne : tout ce que vous devez savoir en 2026Chicken Road – Tragamonedas de casino en lnea que convierte los cruces de gallinas en ganancias.730Chicken Road – Tragamonedas de casino en lnea que combina humor y grandes premios de gallinas.635Официальный сайт Pinco Casino играть онлайн – Вход Зеркало.12423– Официальный сайт Pinco Casino.12085