Changeset 3475999
- Timestamp:
- 03/05/2026 11:58:15 PM (8 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
jrb-remote-site-api-for-openclaw/trunk/jrb-remote-site-api-openclaw.php
r3475991 r3475999 69 69 // Self-update API endpoint 70 70 add_action('rest_api_init', function() { 71 // register_rest_route("openclaw/v1", "/self-update"', [72 register_rest_route("openclaw/v1", "/self-update", [71 // jrb_register_rest_route("jrb/v1", "/self-update"', [ 72 jrb_register_rest_route("jrb/v1", "/self-update", [ 73 73 'callback' => 'openclaw_self_update', 74 74 'permission_callback' => function() { return openclaw_verify_token_and_can('plugins_update'); }, … … 76 76 77 77 // Direct update from URL (allows external push) 78 // register_rest_route("openclaw/v1", "/self-update"-from-url', [79 register_rest_route("openclaw/v1", "/self-update-from-url", [78 // jrb_register_rest_route("jrb/v1", "/self-update"-from-url', [ 79 jrb_register_rest_route("jrb/v1", "/self-update-from-url", [ 80 80 'callback' => 'openclaw_self_update_from_url', 81 81 'permission_callback' => function() { return openclaw_verify_token_and_can('plugins_update'); }, … … 236 236 } 237 237 238 /** 239 * Register REST route for BOTH openclaw/v1 and jrb/v1 namespaces 240 * Ensures backward compatibility during transition period 241 */ 242 function jrb_register_rest_route($namespace, $route, $args) { 243 // Register for requested namespace 244 register_rest_route($namespace, $route, $args); 245 246 // Also register for alternate namespace if different 247 $alternate = ($namespace === 'openclaw/v1') ? 'jrb/v1' : 'openclaw/v1'; 248 if ($alternate !== $namespace) { 249 register_rest_route($alternate, $route, $args); 250 } 251 } 252 238 253 add_action('rest_api_init', function() { 239 254 240 255 // Health check (requires valid token) 241 register_rest_route('openclaw/v1', '/ping', [256 jrb_register_rest_route('jrb/v1', '/ping', [ 242 257 'methods' => 'GET', 243 258 'callback' => 'openclaw_ping', … … 246 261 247 262 // Site info 248 register_rest_route('openclaw/v1', '/site', [263 jrb_register_rest_route('jrb/v1', '/site', [ 249 264 'methods' => 'GET', 250 265 'callback' => 'openclaw_get_site', … … 253 268 254 269 // Posts 255 register_rest_route('openclaw/v1', '/posts', [270 jrb_register_rest_route('jrb/v1', '/posts', [ 256 271 'methods' => 'GET', 257 272 'callback' => 'openclaw_get_posts', … … 259 274 ]); 260 275 261 register_rest_route('openclaw/v1', '/posts', [276 jrb_register_rest_route('jrb/v1', '/posts', [ 262 277 'methods' => 'POST', 263 278 'callback' => 'openclaw_create_post', … … 265 280 ]); 266 281 267 register_rest_route('openclaw/v1', '/posts/(?P<id>\d+)', [282 jrb_register_rest_route('jrb/v1', '/posts/(?P<id>\d+)', [ 268 283 'methods' => 'PUT', 269 284 'callback' => 'openclaw_update_post', … … 271 286 ]); 272 287 273 register_rest_route('openclaw/v1', '/posts/(?P<id>\d+)', [288 jrb_register_rest_route('jrb/v1', '/posts/(?P<id>\d+)', [ 274 289 'methods' => 'DELETE', 275 290 'callback' => 'openclaw_delete_post', … … 278 293 279 294 // Categories 280 register_rest_route('openclaw/v1', '/categories', [295 jrb_register_rest_route('jrb/v1', '/categories', [ 281 296 'methods' => 'GET', 282 297 'callback' => 'openclaw_get_categories', … … 284 299 ]); 285 300 286 register_rest_route('openclaw/v1', '/categories', [301 jrb_register_rest_route('jrb/v1', '/categories', [ 287 302 'methods' => 'POST', 288 303 'callback' => 'openclaw_create_category', … … 291 306 292 307 // Tags 293 register_rest_route('openclaw/v1', '/tags', [308 jrb_register_rest_route('jrb/v1', '/tags', [ 294 309 'methods' => 'GET', 295 310 'callback' => 'openclaw_get_tags', … … 297 312 ]); 298 313 299 register_rest_route('openclaw/v1', '/tags', [314 jrb_register_rest_route('jrb/v1', '/tags', [ 300 315 'methods' => 'POST', 301 316 'callback' => 'openclaw_create_tag', … … 303 318 ]); 304 319 305 register_rest_route('openclaw/v1', '/tags/(?P<id>\d+)', [320 jrb_register_rest_route('jrb/v1', '/tags/(?P<id>\d+)', [ 306 321 'methods' => 'PUT', 307 322 'callback' => 'openclaw_update_tag', … … 309 324 ]); 310 325 311 register_rest_route('openclaw/v1', '/tags/(?P<id>\d+)', [326 jrb_register_rest_route('jrb/v1', '/tags/(?P<id>\d+)', [ 312 327 'methods' => 'DELETE', 313 328 'callback' => 'openclaw_delete_tag', … … 319 334 320 335 // Pages 321 register_rest_route('openclaw/v1', '/pages', [336 jrb_register_rest_route('jrb/v1', '/pages', [ 322 337 'methods' => 'GET', 323 338 'callback' => 'openclaw_get_pages', … … 325 340 ]); 326 341 327 register_rest_route('openclaw/v1', '/pages', [342 jrb_register_rest_route('jrb/v1', '/pages', [ 328 343 'methods' => 'POST', 329 344 'callback' => 'openclaw_create_page', … … 331 346 ]); 332 347 333 register_rest_route('openclaw/v1', '/pages/(?P<id>\d+)', [348 jrb_register_rest_route('jrb/v1', '/pages/(?P<id>\d+)', [ 334 349 'methods' => 'PUT', 335 350 'callback' => 'openclaw_update_page', … … 337 352 ]); 338 353 339 register_rest_route('openclaw/v1', '/pages/(?P<id>\d+)', [354 jrb_register_rest_route('jrb/v1', '/pages/(?P<id>\d+)', [ 340 355 'methods' => 'DELETE', 341 356 'callback' => 'openclaw_delete_page', … … 344 359 345 360 // Users 346 register_rest_route('openclaw/v1', '/users', [361 jrb_register_rest_route('jrb/v1', '/users', [ 347 362 'methods' => 'GET', 348 363 'callback' => 'openclaw_get_users', … … 351 366 352 367 // Plugins 353 register_rest_route('openclaw/v1', '/plugins', [368 jrb_register_rest_route('jrb/v1', '/plugins', [ 354 369 'methods' => 'GET', 355 370 'callback' => 'openclaw_get_plugins', … … 357 372 ]); 358 373 359 register_rest_route('openclaw/v1', '/plugins/install', [374 jrb_register_rest_route('jrb/v1', '/plugins/install', [ 360 375 'methods' => 'POST', 361 376 'callback' => 'openclaw_install_plugin', … … 363 378 ]); 364 379 365 register_rest_route('openclaw/v1', '/plugins/upload', [380 jrb_register_rest_route('jrb/v1', '/plugins/upload', [ 366 381 'methods' => 'POST', 367 382 'callback' => 'openclaw_upload_plugin', … … 369 384 ]); 370 385 371 register_rest_route('openclaw/v1', '/plugins/(?P<slug>[^/]+)/activate', [386 jrb_register_rest_route('jrb/v1', '/plugins/(?P<slug>[^/]+)/activate', [ 372 387 'methods' => 'POST', 373 388 'callback' => 'openclaw_activate_plugin', … … 375 390 ]); 376 391 377 register_rest_route('openclaw/v1', '/plugins/(?P<slug>[^/]+)/deactivate', [392 jrb_register_rest_route('jrb/v1', '/plugins/(?P<slug>[^/]+)/deactivate', [ 378 393 'methods' => 'POST', 379 394 'callback' => 'openclaw_deactivate_plugin', … … 381 396 ]); 382 397 383 register_rest_route('openclaw/v1', '/plugins/(?P<slug>[^/]+)/update', [398 jrb_register_rest_route('jrb/v1', '/plugins/(?P<slug>[^/]+)/update', [ 384 399 'methods' => 'POST', 385 400 'callback' => 'openclaw_update_plugin', … … 387 402 ]); 388 403 389 register_rest_route('openclaw/v1', '/plugins/(?P<slug>[^/]+)', [404 jrb_register_rest_route('jrb/v1', '/plugins/(?P<slug>[^/]+)', [ 390 405 'methods' => 'DELETE', 391 406 'callback' => 'openclaw_delete_plugin', … … 394 409 395 410 // Plugin search (WordPress.org) 396 register_rest_route('openclaw/v1', '/plugins/search', [411 jrb_register_rest_route('jrb/v1', '/plugins/search', [ 397 412 'methods' => 'GET', 398 413 'callback' => 'openclaw_search_plugins', … … 405 420 406 421 // List all menus 407 register_rest_route('openclaw/v1', '/menus', [422 jrb_register_rest_route('jrb/v1', '/menus', [ 408 423 'methods' => 'GET', 409 424 'callback' => 'openclaw_get_menus', … … 412 427 413 428 // Get single menu with items 414 register_rest_route('openclaw/v1', '/menus/(?P<id>\d+)', [429 jrb_register_rest_route('jrb/v1', '/menus/(?P<id>\d+)', [ 415 430 'methods' => 'GET', 416 431 'callback' => 'openclaw_get_menu', … … 419 434 420 435 // Create menu 421 register_rest_route('openclaw/v1', '/menus', [436 jrb_register_rest_route('jrb/v1', '/menus', [ 422 437 'methods' => 'POST', 423 438 'callback' => 'openclaw_create_menu', … … 426 441 427 442 // Update menu name 428 register_rest_route('openclaw/v1', '/menus/(?P<id>\d+)', [443 jrb_register_rest_route('jrb/v1', '/menus/(?P<id>\d+)', [ 429 444 'methods' => 'PUT', 430 445 'callback' => 'openclaw_update_menu', … … 433 448 434 449 // Delete menu 435 register_rest_route('openclaw/v1', '/menus/(?P<id>\d+)', [450 jrb_register_rest_route('jrb/v1', '/menus/(?P<id>\d+)', [ 436 451 'methods' => 'DELETE', 437 452 'callback' => 'openclaw_delete_menu', … … 440 455 441 456 // Add menu item 442 register_rest_route('openclaw/v1', '/menus/(?P<id>\d+)/items', [457 jrb_register_rest_route('jrb/v1', '/menus/(?P<id>\d+)/items', [ 443 458 'methods' => 'POST', 444 459 'callback' => 'openclaw_add_menu_item', … … 447 462 448 463 // Remove menu item 449 register_rest_route('openclaw/v1', '/menus/(?P<id>\d+)/items/(?P<item_id>\d+)', [464 jrb_register_rest_route('jrb/v1', '/menus/(?P<id>\d+)/items/(?P<item_id>\d+)', [ 450 465 'methods' => 'DELETE', 451 466 'callback' => 'openclaw_delete_menu_item', … … 454 469 455 470 // Reorder menu items 456 register_rest_route('openclaw/v1', '/menus/(?P<id>\d+)/items', [471 jrb_register_rest_route('jrb/v1', '/menus/(?P<id>\d+)/items', [ 457 472 'methods' => 'PUT', 458 473 'callback' => 'openclaw_reorder_menu_items', … … 465 480 466 481 // Get current active theme 467 register_rest_route('openclaw/v1', '/theme', [482 jrb_register_rest_route('jrb/v1', '/theme', [ 468 483 'methods' => 'GET', 469 484 'callback' => 'openclaw_get_active_theme', … … 472 487 473 488 // List installed themes 474 register_rest_route('openclaw/v1', '/themes', [489 jrb_register_rest_route('jrb/v1', '/themes', [ 475 490 'methods' => 'GET', 476 491 'callback' => 'openclaw_get_themes', … … 479 494 480 495 // Switch active theme 481 register_rest_route('openclaw/v1', '/theme', [496 jrb_register_rest_route('jrb/v1', '/theme', [ 482 497 'methods' => 'PUT', 483 498 'callback' => 'openclaw_switch_theme', … … 486 501 487 502 // Install theme from ZIP URL 488 register_rest_route('openclaw/v1', '/theme/install', [503 jrb_register_rest_route('jrb/v1', '/theme/install', [ 489 504 'methods' => 'POST', 490 505 'callback' => 'openclaw_install_theme_from_url', … … 493 508 494 509 // Delete theme 495 register_rest_route('openclaw/v1', '/themes/(?P<stylesheet>[a-zA-Z0-9\-_]+)', [510 jrb_register_rest_route('jrb/v1', '/themes/(?P<stylesheet>[a-zA-Z0-9\-_]+)', [ 496 511 'methods' => 'DELETE', 497 512 'callback' => 'openclaw_delete_theme',
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)