PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.20
Booktics – Appointment Booking Calendar for Service Businesses v1.0.20
1.0.29 1.0.28 1.0.27 1.0.26 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 All 31 releases
booktics / core / admin / rest-permission-message.php

rest-permission-message.php in Booktics – Appointment Booking Calendar for Service Businesses 1.0.20, at core/admin/rest-permission-message.php

57 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Booktics\Admin;
3
4 if ( ! defined( 'ABSPATH' ) ) exit;
5
6 use Booktics\Contracts\Hookable_Service_Contract;
7 use WP_REST_Response;
8
9 /**
10 * RestPermissionMessage class.
11 *
12 * @package Booktics/Rest_Permission_Message
13 */
14 class Rest_Permission_Message implements Hookable_Service_Contract {
15 /**
16 * Register hooks
17 *
18 * @return void
19 */
20 public function register() {
21 add_filter( 'rest_request_after_callbacks', array( $this, 'modify_rest_permission_message' ), 10, 3 );
22 }
23
24 /**
25 * Modify permission error message
26 *
27 * @return void
28 */
29 public function modify_rest_permission_message( $response, $handler, $request ) {
30
31 $namespace = $request->get_route();
32
33 if ( strpos( $namespace, '/booktics' ) !== 0 ) {
34 return $response;
35 }
36
37 if ( is_wp_error( $response ) ) {
38 $error_data = $response->get_error_data();
39 $status = isset( $error_data['status'] ) ? $error_data['status'] : 401;
40
41 return new WP_REST_Response(
42 array(
43 'success' => 0,
44 'message' => __( 'Unauthorized user', 'booktics' ),
45 'error' => array(
46 'code' => $response->get_error_code(),
47 'type' => 'permission_error',
48 'details' => $response->get_error_message(),
49 ),
50 ), $status
51 );
52 }
53
54 return $response;
55 }
56 }
57