'example-addon', 'name' => __('Example Addon', 'wnw-example-addon'), 'version' => '1.0.0', 'author' => 'WooNooW Team', 'description' => __('Example addon for testing WooNooW integration', 'wnw-example-addon'), 'spa_bundle' => '', // Not needed for this example 'dependencies' => [ 'woocommerce' => '8.0', 'wordpress' => '6.0', ], ]; return $addons; } /** * Register SPA routes */ public static function register_routes($routes) { $base_url = plugin_dir_url(__FILE__); // Main page $routes[] = [ 'path' => '/example', 'component_url' => $base_url . 'dist/ExamplePage.js', 'capability' => 'manage_woocommerce', 'title' => __('Example Addon', 'wnw-example-addon'), ]; // Detail page $routes[] = [ 'path' => '/example/:id', 'component_url' => $base_url . 'dist/ExampleDetail.js', 'capability' => 'manage_woocommerce', 'title' => __('Example Detail', 'wnw-example-addon'), ]; return $routes; } /** * Register navigation items */ public static function register_navigation($tree) { // Add main menu item $tree[] = [ 'key' => 'example', 'label' => __('Example', 'wnw-example-addon'), 'path' => '/example', 'icon' => 'puzzle', // lucide-react icon 'children' => [ [ 'label' => __('All Items', 'wnw-example-addon'), 'mode' => 'spa', 'path' => '/example', ], [ 'label' => __('Settings', 'wnw-example-addon'), 'mode' => 'spa', 'path' => '/example/settings', ], ], ]; return $tree; } /** * Register REST API endpoints */ public static function register_rest_routes() { register_rest_route('woonoow/v1', '/example', [ 'methods' => 'GET', 'callback' => [__CLASS__, 'get_example_data'], 'permission_callback' => function() { return current_user_can('manage_woocommerce'); }, ]); } /** * Get example data (REST endpoint) */ public static function get_example_data($request) { return rest_ensure_response([ 'success' => true, 'message' => __('Example addon is working!', 'wnw-example-addon'), 'data' => [ 'items' => [ ['id' => 1, 'name' => 'Item 1', 'status' => 'active'], ['id' => 2, 'name' => 'Item 2', 'status' => 'active'], ['id' => 3, 'name' => 'Item 3', 'status' => 'inactive'], ], ], ]); } } // Initialize the addon add_action('plugins_loaded', ['WNW_Example_Addon', 'init'], 25);