PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.2.0
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.2.0
4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.5.2 All 199 releases
← All changes | includes/Core/BaseAPI.php +92 -85 3.5.04.2.0 View file →
@@ -8,108 +8,115 @@
8 8 use WPDeveloper\BetterDocs\Utils\Base;
9 9 use WPDeveloper\BetterDocs\Dependencies\DI\Container;
10 10
11 11 abstract class BaseAPI extends Base {
12 - protected $namespace = 'betterdocs';
13 - protected $version = 'v1';
14 - /**
15 - * Summary of settings
16 - * @var Settings
17 - */
18 - protected $settings;
12 + protected $namespace = 'betterdocs';
13 + protected $version = 'v1';
14 + /**
15 + * Summary of settings
16 + * @var Settings
17 + */
18 + protected $settings;
19 19
20 - /**
21 - * Summary of container
22 - * @var Container
23 - */
24 - protected $container;
20 + /**
21 + * Summary of container
22 + * @var Container
23 + */
24 + protected $container;
25 25
26 - public function __construct( Settings $settings, Container $container ) {
27 - $this->settings = $settings;
28 - $this->container = $container;
26 + public function __construct( Settings $settings, Container $container ) {
27 + $this->settings = $settings;
28 + $this->container = $container;
29 29
30 - add_filter( 'rest_prepare_doc_category', [$this, 'rest_prepare_doc_category'], 10, 3 );
31 - }
30 + add_filter( 'rest_prepare_doc_category', [ $this, 'rest_prepare_doc_category' ], 10, 3 );
31 + }
32 32
33 - public function get_namespace() {
34 - return $this->namespace . '/' . $this->version;
35 - }
33 + public function get_namespace() {
34 + return $this->namespace . '/' . $this->version;
35 + }
36 36
37 - public function get( $endpoint, $callback, $args = [] ) {
38 - return $this->register_endpoint( $endpoint, $callback, $args, WP_REST_Server::READABLE );
39 - }
37 + public function get( $endpoint, $callback, $args = [] ) {
38 + return $this->register_endpoint( $endpoint, $callback, $args, WP_REST_Server::READABLE );
39 + }
40 40
41 - public function post( $endpoint, $callback, $args = [] ) {
42 - return $this->register_endpoint( $endpoint, $callback, $args );
43 - }
41 + public function post( $endpoint, $callback, $args = [] ) {
42 + return $this->register_endpoint( $endpoint, $callback, $args );
43 + }
44 44
45 - public function permission_check() {
46 - return true;
47 - }
45 + public function permission_check() {
46 + return true;
47 + }
48 48
49 - protected function register_endpoint( $endpoint, $callback, $args = [], $methods = WP_REST_Server::CREATABLE ) {
50 - return register_rest_route( $this->get_namespace(), $endpoint, [
51 - 'methods' => $methods,
52 - 'callback' => $callback,
53 - 'permission_callback' => [$this, 'permission_check'],
54 - 'args' => $args
55 - ] );
56 - }
49 + protected function register_endpoint( $endpoint, $callback, $args = [], $methods = WP_REST_Server::CREATABLE ) {
50 + return register_rest_route(
51 + $this->get_namespace(),
52 + $endpoint,
53 + [
54 + 'methods' => $methods,
55 + 'callback' => $callback,
56 + 'permission_callback' => [ $this, 'permission_check' ],
57 + 'args' => $args
58 + ]
59 + );
60 + }
57 61
58 - public function register_field( $type, $attribute, $args = [] ) {
59 - $args = wp_parse_args( $args, [
60 - 'update_callback' => null,
61 - 'schema' => [
62 - 'description' => 'Holds the thumbnail URL of doc category',
63 - 'type' => 'string',
64 - 'format' => 'url'
65 - ]
66 - ] );
62 + public function register_field( $type, $attribute, $args = [] ) {
63 + $args = wp_parse_args(
64 + $args,
65 + [
66 + 'update_callback' => null,
67 + 'schema' => [
68 + 'description' => 'Holds the thumbnail URL of doc category',
69 + 'type' => 'string',
70 + 'format' => 'url'
71 + ]
72 + ]
73 + );
67 74
68 - return register_rest_field( $type, $attribute, $args );
69 - }
75 + return register_rest_field( $type, $attribute, $args );
76 + }
70 77
71 - /**
72 - * @param $data
73 - *
74 - * @return WP_REST_Response
75 - */
76 - public function success( $data ) {
77 - $_data = [
78 - 'success' => true,
79 - 'data' => $data
80 - ];
78 + /**
79 + * @param $data
80 + *
81 + * @return WP_REST_Response
82 + */
83 + public function success( $data ) {
84 + $_data = [
85 + 'success' => true,
86 + 'data' => $data
87 + ];
81 88
82 - if ( is_string( $data ) ) {
83 - $_data['message'] = $data;
89 + if ( is_string( $data ) ) {
90 + $_data['message'] = $data;
84 91
85 - unset( $_data['data'] );
86 - }
92 + unset( $_data['data'] );
93 + }
87 94
88 - return new WP_REST_Response( $_data, 200 );
89 - }
95 + return new WP_REST_Response( $_data, 200 );
96 + }
90 97
91 - /**
92 - * @param $error_code string
93 - * @param $error_message string|array
94 - * @param $endpoint string
95 - * @param $status int
96 - * @param $additional_data array
97 - *
98 - * @return WP_Error
99 - */
100 - public function error( $error_code, $error_message, $status = 500, $additional_data = [] ) {
101 - $additional_data['status'] = $status;
102 - return new WP_Error( $error_code, $error_message, $additional_data );
103 - }
98 + /**
99 + * @param $error_code string
100 + * @param $error_message string|array
101 + * @param $endpoint string
102 + * @param $status int
103 + * @param $additional_data array
104 + *
105 + * @return WP_Error
106 + */
107 + public function error( $error_code, $error_message, $status = 500, $additional_data = [] ) {
108 + $additional_data['status'] = $status;
109 + return new WP_Error( $error_code, $error_message, $additional_data );
110 + }
104 111
105 - abstract public function register();
112 + abstract public function register();
106 113
107 - public function rest_prepare_doc_category( $data, $category, $request ) {
108 - $nested_subcategory = $request->get_param('nested_subcategory', false);
109 - $_counts = betterdocs()->query->get_docs_count( $category, $nested_subcategory );
114 + public function rest_prepare_doc_category( $data, $category, $request ) {
115 + $nested_subcategory = $request->get_param( 'nested_subcategory', false );
116 + $_counts = betterdocs()->query->get_docs_count( $category, $nested_subcategory );
110 117
111 - // Add the custom data to the response
112 - $data->data['count'] = $_counts;
113 - return $data;
114 - }
118 + // Add the custom data to the response
119 + $data->data['count'] = $_counts;
120 + return $data;
121 + }
115 122 }