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