| 1 |
<?php |
| 2 |
/** |
| 3 |
* Send emails in background |
| 4 |
*/ |
| 5 |
defined( 'ABSPATH' ) || exit; |
| 6 |
|
| 7 |
if ( ! class_exists( 'LP_Background_Single_Email' ) ) { |
| 8 |
/** |
| 9 |
* Class LP_Background_Single_Email |
| 10 |
* |
| 11 |
* @since 4.1.1 |
| 12 |
* @author tungnx |
| 13 |
*/ |
| 14 |
class LP_Background_Single_Email extends LP_Async_Request { |
| 15 |
protected $action = 'background_single_email'; |
| 16 |
protected static $instance; |
| 17 |
|
| 18 |
/** |
| 19 |
* Method async handle |
| 20 |
*/ |
| 21 |
protected function handle() { |
| 22 |
$params = LP_Helper::sanitize_params_submitted( $_POST['params'] ?? false ); |
| 23 |
$class_name = LP_Helper::sanitize_params_submitted( $_POST['class_name'] ?? false ); |
| 24 |
|
| 25 |
if ( ! $class_name || ! $params ) { |
| 26 |
error_log( 'Params send email on background is invalid' ); |
| 27 |
|
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
if ( ! class_exists( $class_name ) ) { |
| 32 |
error_log( 'Class not exists: ' . $class_name ); |
| 33 |
|
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
if ( ! method_exists( $class_name, 'handle' ) ) { |
| 38 |
error_log( "Method 'handle' not exists on class $class_name" ); |
| 39 |
|
| 40 |
return; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* @var LP_Email_Type_Enrolled_Course $email |
| 45 |
*/ |
| 46 |
$email = new $class_name; |
| 47 |
$email->handle( $params ); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* @return LP_Background_Single_Email |
| 52 |
*/ |
| 53 |
public static function instance(): self { |
| 54 |
if ( is_null( self::$instance ) ) { |
| 55 |
self::$instance = new self(); |
| 56 |
} |
| 57 |
|
| 58 |
return self::$instance; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
// Must run instance to register ajax. |
| 63 |
LP_Background_Single_Email::instance(); |
| 64 |
} |
| 65 |
|