/**
* 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.htmlHomeIdeal 5 Safest Gambling on line Internet sites in the usa � ComparedMost readily useful 5 Trusted Online gambling Web sites in the us � OpposedDependence on Certification When choosing a safe Into the-range gambling enterpriseBaccarat – since the shown regarding the Seymour toward 1897The fresh Expected Safer Casinos on the internet Having 2025Dependence on Certification When choosing a secure Internet casinoThe fresh Necessary Safer Casinos on the internet Getting 2025Most readily useful 5 Trusted Gambling on line Internet in the usa � ComparedIt Bitcoin gambling enterprise brings out of brief cashouts, with a lot of crypto distributions built in mere minutes!Here, you’ll find harbors, videos black-jack, and much more toward loves out of NetEnt, Microgaming, and you can Play’n WadeMost useful 5 Top Gambling on line Websites in the us � ComparedTo German to try out laws, some one contained in this legal casinos on the internet is located at the fresh new compassion away from a month-to-month set maximum out of �one,100000Choosing a secure For the-line gambling enterprise around australia?Here, discover ports, clips black-jack, and a lot more regarding enjoys out-of NetEnt, Microgaming, and you can Play’n WadeOn the SafeCanada, we carry out offering Canadian pros truthful, outlined evaluations regarding secure web based casinosHow exactly we See Web based casinos become Not risky to Bien au Users?The mandatory Secure Online casinos Getting 2025How exactly to Favor a secure To the-range local casino around australia?Below German betting legislation, advantages at court web based casinos has reached the newest mercy of a monthly put restrict out of �one to,000Safe banking is a vital part of that on the web real money gambling enterpriseHere, you can find harbors, films black-jack, plus in the possess away from NetEnt, Microgaming, and Play’n GoLess than German gaming statutes, benefits about judge casinos on the internet are susceptible to thirty days-to-week place maximum off �step one,100000To play regarding Secure AUS Online casinos � Elite group Tips and tricksIf you’re looking with clear details about every aspect of the current casino’s operating, second take a look at Ignition Gambling enterpriseUnder Italian vocabulary playing regulations, people within court casinos on the internet try susceptible to a month-to-month put limitation from �that,100000The fresh Necessary Secure Online casinos Providing 2025Just how Canadian Personal Shelter Operate Were On line GamblersThe required Secure Online casinos Having 2025Here, select ports, movies black-jack, plus to your wants of NetEnt, Microgaming, and Play’n GoHow to Favor a safe Internet casino in australia?dos. Stacks O’ Progress � Safest Online casino around australia to have PokiesThat it Bitcoin gambling enterprise provides regarding prompt cashouts, with plenty of crypto distributions brought in simple times!Exactly how Canadian Personal Defense Services Include Online BettorsMost useful 5 Trusted Gambling on line Internet sites in the usa � ComparedLess than Italian vocabulary playing guidelines, professionals when you look at the court online casinos was at the mercy of a beneficial month-to-month deposit maximum out-of �step one,100Roulette is actually a famous solutions certainly with the-range gambling establishment Dining table Video gameIf you are searching getting obvious facts about every aspect of the latest casino’s operating, following evaluate Ignition Local casinoRight here, select ports, videos black-jack, as well as on the wishes from NetEnt, Microgaming, and Play’n WadeIf you are looking having apparent information about every aspect of the fresh casino’s operating, following view Ignition Gambling establishmentIf you’re looking providing noticeable information regarding every facet of the latest casino’s performing, next view Ignition Gambling establishmentIdeal 5 Safest Gambling on line Sites in the us � ComparedLegal Land to possess Gambling on line in australiaMost readily useful 5 Respected Online gambling Websites in the us � OpposedThis Bitcoin local casino delivers in terms of punctual cashouts, with a lot of crypto distributions manufactured in simply times!Our very own Called for Secure Web based casinos Bringing 2025How we Like Online casinos become Not harmful to Bien au Players?dos. Stacks O’ Victories � Most secure Into-range local casino in australia with PokiesIn the SafeCanada, we work on providing Canadian members polite, detail by detail reviews from safer web based casinosBaccarat – because the explained on the Seymour inside 1897