/**
* 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.htmlHomeFinest Ports Gambling establishment Review Professional & Pro Evaluations 2026IGTからファラオズラックの無料トライアルをプレイしようTop Online casinos on You S Pro Reviews April 2026Finest Casino: Transcending Online casino Gaming FeelGoogle Enjoy Shop アプリを発見 Google Enjoy LetOnline slots Top Totally free & Trial Games inside the 2026How we Rated the big 50 Gambling establishment Slots in americaBonus Buy Ports Casino Tournament טי וי. פוינט המרכז לכורסאות טלויזיהEnjoy Slot Games Online Most useful Online slotsスフィンクス 5 5 マイルIdeal Online casino Position Online game 2026 Gamble Preferred PortsBetter Web based casinos for real Currency 2026stu Darmowych Spinów z brakiem Depozytu przy nv casino kasynach przez internet ️ Najkorzystniejsze kasyna spośród setka free spinami w naszym krajuPlaisir Avec Salle jouer twin spin emplacements de jeu Plaisir Of Raファラオズ・チャンス スロットマシンゲーム:IGTによる完全無料のスロットゲームをオンラインでプレイDirectory of Sweepstakes Gambling enterprises: Most readily useful Sweeps Casinos to have April 2026Wager On the web Position Games during the South Africa with YesPlay天然貴金属ポジションレビュー 完全無料のデモ機能で楽しみながら、実際の収入を得られますOnline slots games British Gamble 900+ Position Online game The real deal MoneyTop Online slots games & Real cash Position Casino Websites for the April 2026Finest A real income Harbors to tackle when you look at the 2026 Select Finest Slots On the webアイアンマン2ポートレビューGamble on Top 10 Slots On the internet for real Currency Casinos 2026Online casino Uk Play Casino games Online at the Red CasinoWager On line Slot Online game in the Southern Africa with YesPlayダウンロード不要で29,126種類のスロットゲームを楽しもう!This new Members Rating $fifty 100percent freeA real income Online slots gamesBest Real cash Slots On line 2026 Us Finest PicksComment un post à élimination directe nous ne savais loin fabriquer de vrais avec Instagram ? InstagramIdeal No deposit Bonuses 2026 Most useful You Casinos on the internetOn-line casino Gamble A real income Online casino games at GGBet1win официальный сайт букмекерской конторы 1вин.9273Find the best Slots to play On line for real Money On the web HarborsAn informed You Position Internet & Real money Online slots to have 2026Best Personal Gambling establishment Bonuses 2026 No deposit Necessary Free Sweeps Gold coinsレストランカジノでは、入金不要の100%無料ウェルカムボーナスも提供しています。ニューヨーク・トゥデイのリアルマネー#step one Public Slots & Online casino gamesCasino Balade Gratuit : 5 goldbet pour les casinos en ligne sans dépôt Meilleurs Emploi de 2026Silver Fish Harbors Gambling games Applications on google Gamble100 percent free Ports: Enjoy 9,000+ Free online Slot Online game Zero Down loadOnline slots games Better Totally free & Demo Video game in 2026Enjoy 560+ Free Position Online game On the internet, No Signal-Upwards or ObtainDarmowe Spiny w całej polskich kasynach 2025 Kody pod free nv casino spinsFree Harbors On the internet Gamble 100 percent free Slot Video game On linePlay 31,000+ Free Slots & Games No deposit No Down loadTiptop Bet: Quick‑Fire Slots en Fast‑Track Wins voor de Moderne GokkerInterest Needed! CloudflareOn line Slot machines having Bonus Series & Game