feat: Add in-app documentation system

Phase 1: Core Documentation
- Created docs/ folder with 8 markdown documentation files
- Getting Started, Installation, Troubleshooting, FAQ
- Configuration docs (Appearance, SPA Mode)
- Feature docs (Shop, Checkout)
- PHP registry with filter hook for addon extensibility

Phase 2: Documentation Viewer
- DocsController.php with REST API endpoints
- GET /woonoow/v1/docs - List all docs (with addon hook)
- GET /woonoow/v1/docs/{slug} - Get document content
- Admin SPA /help route with sidebar navigation
- Markdown rendering with react-markdown
- Added Help & Docs to More page for mobile access

Filter Hook: woonoow_docs_registry
Addons can register their own documentation sections.
This commit is contained in:
Dwindi Ramadhana
2026-01-04 11:43:32 +07:00
parent 1206117df1
commit 68c3423f50
18 changed files with 3083 additions and 4 deletions

View File

@@ -0,0 +1,129 @@
<?php
/**
* Documentation API Controller
*
* Serves documentation content to the Admin SPA.
*/
namespace WooNooW\Api;
use WP_REST_Controller;
use WP_REST_Response;
use WP_REST_Request;
use WP_Error;
class DocsController extends WP_REST_Controller {
/**
* Namespace for REST routes
*/
protected $namespace = 'woonoow/v1';
/**
* Base route
*/
protected $rest_base = 'docs';
/**
* Register routes
*/
public function register_routes() {
// GET /woonoow/v1/docs - List all documentation
register_rest_route($this->namespace, '/' . $this->rest_base, [
[
'methods' => 'GET',
'callback' => [$this, 'get_docs_registry'],
'permission_callback' => [$this, 'check_permissions'],
],
]);
// GET /woonoow/v1/docs/{slug} - Get single document
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<slug>.+)', [
[
'methods' => 'GET',
'callback' => [$this, 'get_doc'],
'permission_callback' => [$this, 'check_permissions'],
'args' => [
'slug' => [
'required' => true,
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
],
],
],
]);
}
/**
* Check permissions - any logged in admin user
*/
public function check_permissions($request) {
return current_user_can('manage_options');
}
/**
* Get documentation registry
*
* @return WP_REST_Response
*/
public function get_docs_registry($request) {
require_once WOONOOW_PLUGIN_DIR . 'docs/_registry.php';
$registry = \WooNooW\Docs\get_docs_registry();
// Transform to frontend format (without file paths)
$result = [];
foreach ($registry as $section_key => $section) {
$items = [];
foreach ($section['items'] as $item) {
$items[] = [
'slug' => $item['slug'],
'title' => $item['title'],
];
}
$result[] = [
'key' => $section_key,
'label' => $section['label'],
'icon' => $section['icon'] ?? 'file-text',
'items' => $items,
];
}
return new WP_REST_Response([
'success' => true,
'sections' => $result,
], 200);
}
/**
* Get single document content
*
* @param WP_REST_Request $request
* @return WP_REST_Response|WP_Error
*/
public function get_doc($request) {
$slug = $request->get_param('slug');
require_once WOONOOW_PLUGIN_DIR . 'docs/_registry.php';
$doc = \WooNooW\Docs\get_doc_by_slug($slug);
if (!$doc) {
return new WP_Error(
'doc_not_found',
'Documentation not found',
['status' => 404]
);
}
return new WP_REST_Response([
'success' => true,
'doc' => [
'slug' => $doc['slug'],
'title' => $doc['title'],
'content' => $doc['content'],
],
], 200);
}
}