# code-block-pro/1.28.0/php/router.php

Code Block Pro – Beautiful Syntax Highlighting, version 1.28.0. 50 lines.

- Page: https://pluginprobe.com/plugins/code-block-pro/1.28.0/code/php/router.php
- Raw: https://pluginprobe.com/plugins/code-block-pro/1.28.0/raw/php/router.php
- Modified: 2023-03-27T00:10:42+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/code-block-pro/1.28.0/code/php/router.php#L10-L20`.

```php
<?php
defined('ABSPATH') or die;

if (!class_exists('CBPRouter')) {
    class CBPRouter extends \WP_REST_Controller
    {
        protected static $instance = null;
        protected $namespace = 'code-block-pro/v1';
        protected $capability = 'edit_posts';
        public function getHandler($namespace, $endpoint, $callback)
        {
            \register_rest_route(
                $namespace,
                $endpoint,
                [
                    'methods' => 'GET',
                    'callback' => $callback,
                    'permission_callback' => function () {
                        return \current_user_can($this->capability);
                    },
                ]
            );
        }
        public function postHandler($namespace, $endpoint, $callback)
        {
            \register_rest_route(
                $namespace,
                $endpoint,
                [
                    'methods' => 'POST',
                    'callback' => $callback,
                    'permission_callback' => function () {
                        return \current_user_can($this->capability);
                    },
                ]
            );
        }

        public static function __callStatic($name, array $arguments)
        {
            $name = "{$name}Handler";
            if (is_null(self::$instance)) {
                self::$instance = new static();
            }
            $r = self::$instance;
            return $r->$name($r->namespace, ...$arguments);
        }
    }
}

```
