| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentSupport\App\Services; |
| 4 |
|
| 5 |
use FluentSupport\App\Models\Customer; |
| 6 |
|
| 7 |
class ProfileInfoService |
| 8 |
{ |
| 9 |
public static function getProfileExtraWidgets( $customer ) |
| 10 |
{ |
| 11 |
$widgets = []; |
| 12 |
/* |
| 13 |
* Filter customer profile widgets |
| 14 |
* |
| 15 |
* @since v1.0.0 |
| 16 |
* @param array $widgets |
| 17 |
* @param object|array $customer |
| 18 |
* |
| 19 |
* @return void |
| 20 |
*/ |
| 21 |
$widgets = apply_filters('fluent_support/customer_extra_widgets', $widgets, $customer); |
| 22 |
return $widgets; |
| 23 |
} |
| 24 |
|
| 25 |
// This method is linked with 'profile_update' action & it will trigger when user update profile |
| 26 |
public function onWPProfileUpdate( $userId, $userOldData, $userUpdatedData ) |
| 27 |
{ |
| 28 |
if ( !$userId ) { |
| 29 |
return false; |
| 30 |
} |
| 31 |
|
| 32 |
$customer = Customer::where( 'user_id', $userId ); |
| 33 |
|
| 34 |
if ( $customer->count() == 0 ) { |
| 35 |
return false; |
| 36 |
} |
| 37 |
|
| 38 |
$keys = ['first_name', 'last_name', 'user_email']; |
| 39 |
$data = []; |
| 40 |
|
| 41 |
if( !array_diff_key( array_flip($keys), $userUpdatedData ) ) { |
| 42 |
$data = [ |
| 43 |
'first_name' => $userUpdatedData['first_name'], |
| 44 |
'last_name' => $userUpdatedData['last_name'], |
| 45 |
'email' => $userUpdatedData['user_email'], |
| 46 |
]; |
| 47 |
}; |
| 48 |
|
| 49 |
if ( count($data) > 0 ) { |
| 50 |
$customer->update($data); |
| 51 |
} |
| 52 |
|
| 53 |
} |
| 54 |
} |
| 55 |
|