UserProfileService.php
54 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\WordPress\Admin\Profile; |
| 4 | |
| 5 | use SureCart\Models\User; |
| 6 | |
| 7 | /** |
| 8 | * Admin user profile service |
| 9 | */ |
| 10 | class UserProfileService { |
| 11 | /** |
| 12 | * Bootstrap related hooks. |
| 13 | * |
| 14 | * @return void |
| 15 | */ |
| 16 | public function bootstrap() { |
| 17 | add_action( 'edit_user_profile', [ $this, 'showCustomerInfo' ] ); |
| 18 | add_action( 'show_user_profile', [ $this, 'showCustomerInfo' ] ); |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Show customer info on user profile. |
| 23 | * |
| 24 | * @param \WP_User $user The user. |
| 25 | * @return void |
| 26 | */ |
| 27 | public function showCustomerInfo( $user ) { |
| 28 | $user = User::find( $user->ID ); |
| 29 | $test_customer = $user->customer( 'test' ); |
| 30 | $live_customer = $user->customer( 'live' ); |
| 31 | |
| 32 | $this->render( |
| 33 | 'admin/user-profile', |
| 34 | [ |
| 35 | 'test_customer' => $test_customer, |
| 36 | 'live_customer' => $live_customer, |
| 37 | 'edit_test_link' => is_a( $test_customer, \SureCart\Models\Customer::class ) ? \SureCart::getUrl()->edit( 'customer', $test_customer->id ) : '', |
| 38 | 'edit_live_link' => is_a( $live_customer, \SureCart\Models\Customer::class ) ? \SureCart::getUrl()->edit( 'customer', $live_customer->id ) : '', |
| 39 | ] |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Render a block using a template |
| 45 | * |
| 46 | * @param string|string[] $views A view or array of views. |
| 47 | * @param array<string, mixed> $context Context to send. |
| 48 | * @return void |
| 49 | */ |
| 50 | public function render( $views, $context = [] ) { |
| 51 | echo wp_kses_post( \SureCart::views()->make( $views )->with( $context )->toString() ); |
| 52 | } |
| 53 | } |
| 54 |