Plugin Directory

Changeset 3475999


Ignore:
Timestamp:
03/05/2026 11:58:15 PM (8 months ago)
Author:
jrbconsulting
Message:

v6.5.1: Fix dual namespace registration (jrb/v1 + openclaw/v1)

FIX:

  • Added jrb_register_rest_route() helper function
  • All endpoints now registered for BOTH jrb/v1 AND openclaw/v1
  • Backward compatibility maintained during transition

Previously only openclaw/v1 was registered. Now both namespaces work.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • jrb-remote-site-api-for-openclaw/trunk/jrb-remote-site-api-openclaw.php

    r3475991 r3475999  
    6969// Self-update API endpoint
    7070add_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", [
    7373        'callback' => 'openclaw_self_update',
    7474        'permission_callback' => function() { return openclaw_verify_token_and_can('plugins_update'); },
    … …  
    7676   
    7777    // 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", [
    8080        'callback' => 'openclaw_self_update_from_url',
    8181        'permission_callback' => function() { return openclaw_verify_token_and_can('plugins_update'); },
    … …  
    236236}
    237237
     238/**
     239 * Register REST route for BOTH openclaw/v1 and jrb/v1 namespaces
     240 * Ensures backward compatibility during transition period
     241 */
     242function 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
    238253add_action('rest_api_init', function() {
    239254   
    240255    // Health check (requires valid token)
    241     register_rest_route('openclaw/v1', '/ping', [
     256    jrb_register_rest_route('jrb/v1', '/ping', [
    242257        'methods' => 'GET',
    243258        'callback' => 'openclaw_ping',
    … …  
    246261   
    247262    // Site info
    248     register_rest_route('openclaw/v1', '/site', [
     263    jrb_register_rest_route('jrb/v1', '/site', [
    249264        'methods' => 'GET',
    250265        'callback' => 'openclaw_get_site',
    … …  
    253268   
    254269    // Posts
    255     register_rest_route('openclaw/v1', '/posts', [
     270    jrb_register_rest_route('jrb/v1', '/posts', [
    256271        'methods' => 'GET',
    257272        'callback' => 'openclaw_get_posts',
    … …  
    259274    ]);
    260275   
    261     register_rest_route('openclaw/v1', '/posts', [
     276    jrb_register_rest_route('jrb/v1', '/posts', [
    262277        'methods' => 'POST',
    263278        'callback' => 'openclaw_create_post',
    … …  
    265280    ]);
    266281   
    267     register_rest_route('openclaw/v1', '/posts/(?P<id>\d+)', [
     282    jrb_register_rest_route('jrb/v1', '/posts/(?P<id>\d+)', [
    268283        'methods' => 'PUT',
    269284        'callback' => 'openclaw_update_post',
    … …  
    271286    ]);
    272287   
    273     register_rest_route('openclaw/v1', '/posts/(?P<id>\d+)', [
     288    jrb_register_rest_route('jrb/v1', '/posts/(?P<id>\d+)', [
    274289        'methods' => 'DELETE',
    275290        'callback' => 'openclaw_delete_post',
    … …  
    278293   
    279294    // Categories
    280     register_rest_route('openclaw/v1', '/categories', [
     295    jrb_register_rest_route('jrb/v1', '/categories', [
    281296        'methods' => 'GET',
    282297        'callback' => 'openclaw_get_categories',
    … …  
    284299    ]);
    285300   
    286     register_rest_route('openclaw/v1', '/categories', [
     301    jrb_register_rest_route('jrb/v1', '/categories', [
    287302        'methods' => 'POST',
    288303        'callback' => 'openclaw_create_category',
    … …  
    291306   
    292307    // Tags
    293     register_rest_route('openclaw/v1', '/tags', [
     308    jrb_register_rest_route('jrb/v1', '/tags', [
    294309        'methods' => 'GET',
    295310        'callback' => 'openclaw_get_tags',
    … …  
    297312    ]);
    298313   
    299     register_rest_route('openclaw/v1', '/tags', [
     314    jrb_register_rest_route('jrb/v1', '/tags', [
    300315        'methods' => 'POST',
    301316        'callback' => 'openclaw_create_tag',
    … …  
    303318    ]);
    304319   
    305     register_rest_route('openclaw/v1', '/tags/(?P<id>\d+)', [
     320    jrb_register_rest_route('jrb/v1', '/tags/(?P<id>\d+)', [
    306321        'methods' => 'PUT',
    307322        'callback' => 'openclaw_update_tag',
    … …  
    309324    ]);
    310325   
    311     register_rest_route('openclaw/v1', '/tags/(?P<id>\d+)', [
     326    jrb_register_rest_route('jrb/v1', '/tags/(?P<id>\d+)', [
    312327        'methods' => 'DELETE',
    313328        'callback' => 'openclaw_delete_tag',
    … …  
    319334   
    320335    // Pages
    321     register_rest_route('openclaw/v1', '/pages', [
     336    jrb_register_rest_route('jrb/v1', '/pages', [
    322337        'methods' => 'GET',
    323338        'callback' => 'openclaw_get_pages',
    … …  
    325340    ]);
    326341   
    327     register_rest_route('openclaw/v1', '/pages', [
     342    jrb_register_rest_route('jrb/v1', '/pages', [
    328343        'methods' => 'POST',
    329344        'callback' => 'openclaw_create_page',
    … …  
    331346    ]);
    332347   
    333     register_rest_route('openclaw/v1', '/pages/(?P<id>\d+)', [
     348    jrb_register_rest_route('jrb/v1', '/pages/(?P<id>\d+)', [
    334349        'methods' => 'PUT',
    335350        'callback' => 'openclaw_update_page',
    … …  
    337352    ]);
    338353   
    339     register_rest_route('openclaw/v1', '/pages/(?P<id>\d+)', [
     354    jrb_register_rest_route('jrb/v1', '/pages/(?P<id>\d+)', [
    340355        'methods' => 'DELETE',
    341356        'callback' => 'openclaw_delete_page',
    … …  
    344359   
    345360    // Users
    346     register_rest_route('openclaw/v1', '/users', [
     361    jrb_register_rest_route('jrb/v1', '/users', [
    347362        'methods' => 'GET',
    348363        'callback' => 'openclaw_get_users',
    … …  
    351366   
    352367    // Plugins
    353     register_rest_route('openclaw/v1', '/plugins', [
     368    jrb_register_rest_route('jrb/v1', '/plugins', [
    354369        'methods' => 'GET',
    355370        'callback' => 'openclaw_get_plugins',
    … …  
    357372    ]);
    358373   
    359     register_rest_route('openclaw/v1', '/plugins/install', [
     374    jrb_register_rest_route('jrb/v1', '/plugins/install', [
    360375        'methods' => 'POST',
    361376        'callback' => 'openclaw_install_plugin',
    … …  
    363378    ]);
    364379
    365     register_rest_route('openclaw/v1', '/plugins/upload', [
     380    jrb_register_rest_route('jrb/v1', '/plugins/upload', [
    366381        'methods' => 'POST',
    367382        'callback' => 'openclaw_upload_plugin',
    … …  
    369384    ]);
    370385   
    371     register_rest_route('openclaw/v1', '/plugins/(?P<slug>[^/]+)/activate', [
     386    jrb_register_rest_route('jrb/v1', '/plugins/(?P<slug>[^/]+)/activate', [
    372387        'methods' => 'POST',
    373388        'callback' => 'openclaw_activate_plugin',
    … …  
    375390    ]);
    376391   
    377     register_rest_route('openclaw/v1', '/plugins/(?P<slug>[^/]+)/deactivate', [
     392    jrb_register_rest_route('jrb/v1', '/plugins/(?P<slug>[^/]+)/deactivate', [
    378393        'methods' => 'POST',
    379394        'callback' => 'openclaw_deactivate_plugin',
    … …  
    381396    ]);
    382397   
    383     register_rest_route('openclaw/v1', '/plugins/(?P<slug>[^/]+)/update', [
     398    jrb_register_rest_route('jrb/v1', '/plugins/(?P<slug>[^/]+)/update', [
    384399        'methods' => 'POST',
    385400        'callback' => 'openclaw_update_plugin',
    … …  
    387402    ]);
    388403   
    389     register_rest_route('openclaw/v1', '/plugins/(?P<slug>[^/]+)', [
     404    jrb_register_rest_route('jrb/v1', '/plugins/(?P<slug>[^/]+)', [
    390405        'methods' => 'DELETE',
    391406        'callback' => 'openclaw_delete_plugin',
    … …  
    394409   
    395410    // Plugin search (WordPress.org)
    396     register_rest_route('openclaw/v1', '/plugins/search', [
     411    jrb_register_rest_route('jrb/v1', '/plugins/search', [
    397412        'methods' => 'GET',
    398413        'callback' => 'openclaw_search_plugins',
    … …  
    405420   
    406421    // List all menus
    407     register_rest_route('openclaw/v1', '/menus', [
     422    jrb_register_rest_route('jrb/v1', '/menus', [
    408423        'methods' => 'GET',
    409424        'callback' => 'openclaw_get_menus',
    … …  
    412427   
    413428    // 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+)', [
    415430        'methods' => 'GET',
    416431        'callback' => 'openclaw_get_menu',
    … …  
    419434   
    420435    // Create menu
    421     register_rest_route('openclaw/v1', '/menus', [
     436    jrb_register_rest_route('jrb/v1', '/menus', [
    422437        'methods' => 'POST',
    423438        'callback' => 'openclaw_create_menu',
    … …  
    426441   
    427442    // Update menu name
    428     register_rest_route('openclaw/v1', '/menus/(?P<id>\d+)', [
     443    jrb_register_rest_route('jrb/v1', '/menus/(?P<id>\d+)', [
    429444        'methods' => 'PUT',
    430445        'callback' => 'openclaw_update_menu',
    … …  
    433448   
    434449    // Delete menu
    435     register_rest_route('openclaw/v1', '/menus/(?P<id>\d+)', [
     450    jrb_register_rest_route('jrb/v1', '/menus/(?P<id>\d+)', [
    436451        'methods' => 'DELETE',
    437452        'callback' => 'openclaw_delete_menu',
    … …  
    440455   
    441456    // 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', [
    443458        'methods' => 'POST',
    444459        'callback' => 'openclaw_add_menu_item',
    … …  
    447462   
    448463    // 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+)', [
    450465        'methods' => 'DELETE',
    451466        'callback' => 'openclaw_delete_menu_item',
    … …  
    454469   
    455470    // 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', [
    457472        'methods' => 'PUT',
    458473        'callback' => 'openclaw_reorder_menu_items',
    … …  
    465480   
    466481    // Get current active theme
    467     register_rest_route('openclaw/v1', '/theme', [
     482    jrb_register_rest_route('jrb/v1', '/theme', [
    468483        'methods' => 'GET',
    469484        'callback' => 'openclaw_get_active_theme',
    … …  
    472487   
    473488    // List installed themes
    474     register_rest_route('openclaw/v1', '/themes', [
     489    jrb_register_rest_route('jrb/v1', '/themes', [
    475490        'methods' => 'GET',
    476491        'callback' => 'openclaw_get_themes',
    … …  
    479494   
    480495    // Switch active theme
    481     register_rest_route('openclaw/v1', '/theme', [
     496    jrb_register_rest_route('jrb/v1', '/theme', [
    482497        'methods' => 'PUT',
    483498        'callback' => 'openclaw_switch_theme',
    … …  
    486501   
    487502    // Install theme from ZIP URL
    488     register_rest_route('openclaw/v1', '/theme/install', [
     503    jrb_register_rest_route('jrb/v1', '/theme/install', [
    489504        'methods' => 'POST',
    490505        'callback' => 'openclaw_install_theme_from_url',
    … …  
    493508   
    494509    // 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\-_]+)', [
    496511        'methods' => 'DELETE',
    497512        'callback' => 'openclaw_delete_theme',
Note: See TracChangeset for help on using the changeset viewer.