| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class LP_Email_Become_An_Instructor |
| 4 |
* |
| 5 |
* @author ThimPress |
| 6 |
* @package LearnPress/Classes |
| 7 |
* @version 3.0.1 |
| 8 |
* @author tungnx |
| 9 |
* @modify 4.1.3 |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* Prevent loading this file directly |
| 14 |
*/ |
| 15 |
defined( 'ABSPATH' ) || exit(); |
| 16 |
|
| 17 |
if ( ! class_exists( 'LP_Email_Become_An_Instructor' ) ) { |
| 18 |
class LP_Email_Become_An_Instructor extends LP_Email { |
| 19 |
/** |
| 20 |
* LP_Email_Become_An_Instructor constructor. |
| 21 |
*/ |
| 22 |
public function __construct() { |
| 23 |
$this->id = 'become-an-instructor'; |
| 24 |
$this->title = __( 'Request', 'learnpress' ); |
| 25 |
$this->description = __( 'Become an instructor email.', 'learnpress' ); |
| 26 |
|
| 27 |
$this->default_subject = __( '[{{site_title}}] Request to become an instructor', 'learnpress' ); |
| 28 |
$this->default_heading = __( 'Become an instructor', 'learnpress' ); |
| 29 |
|
| 30 |
parent::__construct(); |
| 31 |
|
| 32 |
$variable_on_email_support = apply_filters( |
| 33 |
'lp/email/become-an-instructor/variables-support', |
| 34 |
[ |
| 35 |
'{{request_email}}', |
| 36 |
'{{request_phone}}', |
| 37 |
'{{request_message}}', |
| 38 |
'{{admin_user_manager}}', |
| 39 |
'{{accept_url}}', |
| 40 |
'{{deny_url}}', |
| 41 |
] |
| 42 |
); |
| 43 |
|
| 44 |
$this->support_variables = array_merge( $this->support_variables, $variable_on_email_support ); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Check email enable option |
| 49 |
* Check param valid: 4 params: bat_name, bat_email, bat_phone, bat_message |
| 50 |
* Set values |
| 51 |
* |
| 52 |
* @param array $params |
| 53 |
* @throws Exception |
| 54 |
*/ |
| 55 |
public function handle( array $params ) { |
| 56 |
if ( ! $this->enable ) { |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
if ( count( $params ) < 1 ) { |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
if ( ! $this->set_data_content( $params[0] ) ) { |
| 65 |
return; |
| 66 |
} |
| 67 |
$this->set_receive( $this->_get_admin_email() ); |
| 68 |
$this->send_email(); |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Set data content |
| 73 |
*/ |
| 74 |
protected function set_data_content( $params ): bool { |
| 75 |
$bat_email = $params['bat_email'] ?? ''; |
| 76 |
$bat_phone = $params['bat_phone'] ?? ''; |
| 77 |
$bat_message = $params['bat_message'] ?? ''; |
| 78 |
|
| 79 |
$user = get_user_by( 'email', $bat_email ); |
| 80 |
if ( ! $user ) { |
| 81 |
return false; |
| 82 |
} |
| 83 |
|
| 84 |
$this->variables = apply_filters( |
| 85 |
'lp/email/type-become-an-instructor-admin/variables-mapper', |
| 86 |
[ |
| 87 |
'{{request_email}}' => $bat_email, |
| 88 |
'{{request_phone}}' => $bat_phone, |
| 89 |
'{{request_message}}' => $bat_message, |
| 90 |
'{{admin_user_manager}}' => admin_url( 'users.php?lp-action=pending-request' ), |
| 91 |
'{{accept_url}}' => admin_url( 'users.php?lp-action=accept-request&user_id=' . $user->ID ), |
| 92 |
'{{deny_url}}' => admin_url( 'users.php?lp-action=deny-request&user_id=' . $user->ID ), |
| 93 |
] |
| 94 |
); |
| 95 |
|
| 96 |
$variables_common = $this->get_common_variables( $this->email_format ); |
| 97 |
$this->variables = array_merge( $this->variables, $variables_common ); |
| 98 |
|
| 99 |
return true; |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
return new LP_Email_Become_An_Instructor(); |
| 104 |
} |
| 105 |
|
| 106 |
|