| | |
| | | <?php |
| | | namespace JVBase\rest\routes; |
| | | |
| | | use JVBase\rest\RestRouteManager; |
| | | use JVBase\rest\Rest; |
| | | use JVBase\managers\Cache; |
| | | use JVBase\managers\SEO\ConfigManager; |
| | | use JVBase\managers\SEO\SchemaBuilder; |
| | | use JVBase\rest\Route; |
| | | use WP_REST_Request; |
| | | use WP_REST_Response; |
| | | use WP_Error; |
| | |
| | | * Handles REST API endpoints for SEO configuration |
| | | * Works with FormController.js for unified form handling |
| | | */ |
| | | class SEORoutes extends RestRouteManager |
| | | class SEORoutes extends Rest |
| | | { |
| | | protected SchemaBuilder $registry; |
| | | |
| | | public function __construct() |
| | | { |
| | | $this->cache_name = 'schema'; |
| | | $this->cacheName = 'schema'; |
| | | parent::__construct(); |
| | | $this->registry = SchemaBuilder::getInstance(); |
| | | } |
| | |
| | | */ |
| | | public function registerRoutes(): void |
| | | { |
| | | // Main SEO endpoint - handles save, reset, preview |
| | | register_rest_route($this->namespace, '/seo', [ |
| | | [ |
| | | 'methods' => 'POST', |
| | | 'callback' => [$this, 'handleSEO'], |
| | | 'permission_callback' => fn() => current_user_can('manage_options'), |
| | | 'args' => [ |
| | | 'action' => [ |
| | | 'required' => false, |
| | | 'type' => 'string', |
| | | 'default' => 'save', |
| | | 'enum' => ['save', 'reset', 'preview'] |
| | | ], |
| | | 'context' => [ |
| | | 'required' => true, |
| | | 'type' => 'string', |
| | | 'description' => 'site, business, or content/taxonomy/user type' |
| | | ] |
| | | ] |
| | | ] |
| | | ]); |
| | | Route::for('seo') |
| | | ->post([$this, 'handleSEO']) |
| | | ->auth('admin') |
| | | ->args([ |
| | | 'action' => 'string|required|enum:save,reset,preview', |
| | | 'context'=> 'string|required' |
| | | ]) |
| | | ->rateLimit(30); |
| | | |
| | | // Get fields for a schema type (for dynamic type switching) |
| | | register_rest_route($this->namespace, '/seo/fields', [ |
| | | [ |
| | | 'methods' => 'GET', |
| | | 'callback' => [$this, 'getFields'], |
| | | 'permission_callback' => fn() => current_user_can('manage_options'), |
| | | 'args' => [ |
| | | 'type' => [ |
| | | 'required' => true, |
| | | 'type' => 'string' |
| | | ] |
| | | ] |
| | | ] |
| | | ]); |
| | | Route::for('seo/fields') |
| | | ->get([$this, 'getFields']) |
| | | ->auth('admin') |
| | | ->args([ |
| | | 'type'=>'string|required' |
| | | ]); |
| | | } |
| | | |
| | | /** |
| | |
| | | // Invalidate cache |
| | | $this->cache->flush(); |
| | | |
| | | return new WP_REST_Response([ |
| | | 'success' => true, |
| | | 'status' => 'completed', |
| | | 'message' => ucfirst($context) . ' settings saved successfully' |
| | | ]); |
| | | return$this->success(['message'=>ucfirst($context).' settings saved successfully']); |
| | | } |
| | | |
| | | /** |
| | |
| | | // Invalidate cache |
| | | $this->cache->flush(); |
| | | |
| | | return new WP_REST_Response([ |
| | | 'success' => true, |
| | | 'status' => 'completed', |
| | | 'message' => 'Configuration saved successfully' |
| | | ]); |
| | | return $this->success(['status'=> 'completed', 'message' => 'Configuration saved successfully']); |
| | | } |
| | | |
| | | /** |
| | |
| | | // Invalidate cache |
| | | $this->cache->flush(); |
| | | |
| | | return new WP_REST_Response([ |
| | | 'success' => true, |
| | | return $this->success([ |
| | | 'status' => 'completed', |
| | | 'message' => 'Reset to defaults successfully', |
| | | 'meta' => $config->meta(), |
| | |
| | | $schema[$fieldName] = $value; |
| | | } |
| | | |
| | | return new WP_REST_Response([ |
| | | 'success' => true, |
| | | return $this->success([ |
| | | 'schema' => $schema |
| | | ]); |
| | | } |
| | |
| | | { |
| | | $type = $request->get_param('type'); |
| | | |
| | | // Get MetaManager field definitions from registry |
| | | // Get Meta field definitions from registry |
| | | $fields = $this->registry->getMetaConfigForType($type); |
| | | |
| | | return new WP_REST_Response($fields); |
| | | return $this->success($fields); |
| | | } |
| | | |
| | | /** |