| 1 |
<?php |
| 2 |
|
| 3 |
namespace Booktics\Customer\Handlers; |
| 4 |
|
| 5 |
use Booktics\Models\Customer_Model; |
| 6 |
|
| 7 |
class Customer_Event_Handler { |
| 8 |
|
| 9 |
/** |
| 10 |
* Send invitation mail on team member creation |
| 11 |
* |
| 12 |
* @param $team_member_id |
| 13 |
* |
| 14 |
* @return bool |
| 15 |
*/ |
| 16 |
public function on_customer_create( $customer_id ) { |
| 17 |
$customer = ( new Customer_Model() )->find( $customer_id ); |
| 18 |
$user = get_user_by( 'ID', $customer_id ); |
| 19 |
if ( ! $user ) { |
| 20 |
return false; |
| 21 |
} |
| 22 |
$reset_key = get_password_reset_key( $user ); |
| 23 |
$reset_url = network_site_url( "wp-login.php?action=rp&key=$reset_key&login=" . rawurlencode( $user->user_login ), 'login' ); |
| 24 |
|
| 25 |
$subject = 'You’ve been invited!'; |
| 26 |
$message = "Hi {$customer->display_name},\n\nYou’ve been invited to join our platform.\n\n"; |
| 27 |
$message .= 'Reset password : ' . $reset_url . "\n"; |
| 28 |
$message .= 'If this wasn’t you, please ignore this email.'; |
| 29 |
|
| 30 |
$headers = array( 'Content-Type: text/plain; charset=UTF-8' ); |
| 31 |
|
| 32 |
wp_mail( $customer->email, $subject, $message, $headers ); |
| 33 |
|
| 34 |
return true; |
| 35 |
} |
| 36 |
} |
| 37 |
|