# booktics/1.0.20/core/admin/rest-permission-message.php

Booktics – Appointment Booking Calendar for Service Businesses, version 1.0.20. 57 lines.

- Page: https://pluginprobe.com/plugins/booktics/1.0.20/code/core/admin/rest-permission-message.php
- Raw: https://pluginprobe.com/plugins/booktics/1.0.20/raw/core/admin/rest-permission-message.php
- Modified: 2026-04-29T04:49:04+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/booktics/1.0.20/code/core/admin/rest-permission-message.php#L10-L20`.

```php
<?php
namespace Booktics\Admin;

if ( ! defined( 'ABSPATH' ) ) exit;

use Booktics\Contracts\Hookable_Service_Contract;
use WP_REST_Response;

/**
 * RestPermissionMessage class.
 *
 * @package Booktics/Rest_Permission_Message
 */
class Rest_Permission_Message implements Hookable_Service_Contract {
    /**
     * Register hooks
     *
     * @return  void
     */
    public function register() {
        add_filter( 'rest_request_after_callbacks', array( $this, 'modify_rest_permission_message' ), 10, 3 );
    }

    /**
     * Modify permission error message
     *
     * @return  void
     */
    public function modify_rest_permission_message( $response, $handler, $request ) {

        $namespace = $request->get_route();

        if ( strpos( $namespace, '/booktics' ) !== 0 ) {
            return $response;
        }

        if ( is_wp_error( $response ) ) {
            $error_data = $response->get_error_data();
            $status     = isset( $error_data['status'] ) ? $error_data['status'] : 401;

            return new WP_REST_Response(
                array(
					'success' => 0,
					'message' => __( 'Unauthorized user', 'booktics' ),
					'error'   => array(
						'code'    => $response->get_error_code(),
						'type'    => 'permission_error',
						'details' => $response->get_error_message(),
					),
                ), $status
            );
        }

        return $response;
    }
}

```
