PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / trunk
Code Block Pro – Beautiful Syntax Highlighting vtrunk
1.27.1 1.27.2 1.27.3 1.27.4 1.27.5 1.27.6 1.27.7 1.28.0 1.3.0 1.4.0 1.5.0 1.5.1 1.5.2 1.6.0 1.7.0 1.8.0 1.9.0 1.9.1 1.9.2 1.9.3 trunk 1.1.0 1.10.0 1.11.0 1.11.1 All 63 releases
code-block-pro / php / router.php

router.php in Code Block Pro – Beautiful Syntax Highlighting trunk, at php/router.php

50 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') or die;
3
4 if (!class_exists('CBPRouter')) {
5 class CBPRouter extends \WP_REST_Controller
6 {
7 protected static $instance = null;
8 protected $namespace = 'code-block-pro/v1';
9 protected $capability = 'edit_posts';
10 public function getHandler($namespace, $endpoint, $callback)
11 {
12 \register_rest_route(
13 $namespace,
14 $endpoint,
15 [
16 'methods' => 'GET',
17 'callback' => $callback,
18 'permission_callback' => function () {
19 return \current_user_can($this->capability);
20 },
21 ]
22 );
23 }
24 public function postHandler($namespace, $endpoint, $callback)
25 {
26 \register_rest_route(
27 $namespace,
28 $endpoint,
29 [
30 'methods' => 'POST',
31 'callback' => $callback,
32 'permission_callback' => function () {
33 return \current_user_can($this->capability);
34 },
35 ]
36 );
37 }
38
39 public static function __callStatic($name, array $arguments)
40 {
41 $name = "{$name}Handler";
42 if (is_null(self::$instance)) {
43 self::$instance = new static();
44 }
45 $r = self::$instance;
46 return $r->$name($r->namespace, ...$arguments);
47 }
48 }
49 }
50