PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.0
Booktics – Appointment Booking Calendar for Service Businesses v1.0.0
1.0.25 1.0.24 1.0.23 1.0.22 1.0.21 1.0.20 1.0.19 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 All 27 releases
booktics / core / onboard / controllers / onboard-controller.php

onboard-controller.php in Booktics – Appointment Booking Calendar for Service Businesses 1.0.0, at core/onboard/controllers/onboard-controller.php

99 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Booktics\Onboard\Controllers;
3
4 use Booktics\Abstracts\Base_Rest_Controller;
5 use Booktics\Onboard\Onboarding;
6 use WP_REST_Server;
7
8 /**
9 * Onboard controller
10 *
11 * @package Booktics/Onboard
12 */
13 class Onboard_Controller extends Base_Rest_Controller {
14 /**
15 * Endpoint namespace
16 *
17 * @var string
18 */
19 protected $namespace = 'booktics/v1';
20
21 /**
22 * Route name
23 *
24 * @var string
25 */
26 protected $base = 'onboard';
27
28 /**
29 * Register routes
30 *
31 * @return void
32 */
33 public function register_routes(): void {
34 register_rest_route(
35 $this->namespace, $this->base, array(
36 array(
37 'methods' => WP_REST_Server::CREATABLE,
38 'callback' => array( $this, 'setup_profile' ),
39 'permission_callback' => array( $this, 'setup_profile_permissions_check' ),
40 ),
41 )
42 );
43 }
44
45 /**
46 * Setup bussinsess profile
47 *
48 * @param WP_Rest_Request $request Request Object
49 *
50 * @return WP_Rest_Response | WP_Error
51 */
52 public function setup_profile( $request ) {
53 $data = json_decode( $request->get_body(), true );
54
55 $result = Onboarding::update( $data );
56
57 if ( is_wp_error( $result ) ) {
58 return $this->error( $result->get_error_message() );
59 }
60 $message = __( 'Successfully updated business profile', 'booktics' );
61
62 $response = $this->prepare_item_for_response( $data, $request );
63
64 return $this->response( $response, $message );
65 }
66
67 /**
68 * Check permissions for setup profile
69 *
70 * @param WP_Rest_Request $request
71 *
72 * @return WP_Rest_Response | WP_Error
73 */
74 public function setup_profile_permissions_check( $request ): bool {
75 return current_user_can( 'manage_options' );
76 }
77
78 /**
79 * Prepare item for response
80 *
81 * @param array $item Response item
82 * @param array $request Requested data
83 *
84 * @return array Collection of response data
85 */
86 public function prepare_item_for_response( $item, $request ): array {
87 $data = array(
88 'business_email' => Onboarding::get( 'business_email' ),
89 'business_name' => Onboarding::get( 'business_name' ),
90 'business_type' => Onboarding::get( 'business_type' ),
91 'business_timezone' => Onboarding::get( 'business_timezone' ),
92 'schedule' => Onboarding::get( 'schedule' ),
93 'onboard_setup' => Onboarding::get( 'onboard_setup' ),
94 );
95
96 return $data;
97 }
98 }
99