{"action":"created","issue":{"url":"https://api.github.com/repos/WP-API/WP-API/issues/2263","repository_url":"https://api.github.com/repos/WP-API/WP-API","labels_url":"https://api.github.com/repos/WP-API/WP-API/issues/2263/labels{/name}","comments_url":"https://api.github.com/repos/WP-API/WP-API/issues/2263/comments","events_url":"https://api.github.com/repos/WP-API/WP-API/issues/2263/events","html_url":"https://github.com/WP-API/WP-API/issues/2263","id":132819904,"number":2263,"title":"rest_api_init hook only registering the last one","user":{"login":"NizarBlond","id":2389428,"avatar_url":"https://avatars.githubusercontent.com/u/2389428?v=3","gravatar_id":"","url":"https://api.github.com/users/NizarBlond","html_url":"https://github.com/NizarBlond","followers_url":"https://api.github.com/users/NizarBlond/followers","following_url":"https://api.github.com/users/NizarBlond/following{/other_user}","gists_url":"https://api.github.com/users/NizarBlond/gists{/gist_id}","starred_url":"https://api.github.com/users/NizarBlond/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NizarBlond/subscriptions","organizations_url":"https://api.github.com/users/NizarBlond/orgs","repos_url":"https://api.github.com/users/NizarBlond/repos","events_url":"https://api.github.com/users/NizarBlond/events{/privacy}","received_events_url":"https://api.github.com/users/NizarBlond/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-02-10T21:18:11Z","updated_at":"2016-02-10T21:49:29Z","closed_at":null,"body":"\r\nI collect arguments from different classes and then register API routes arguments.\r\nThen, at one time, I iterate over all the args and load them using add_action('rest_api_init', $cb).\r\n\r\n**Problem**: only last args are registered as route (successfully). I checked all of them by changing orders.\r\n\r\nSee code below \r\n\r\nEach class calls this ApiHelper function:\r\n\r\n`public function registerRoute($ns, $route, $component, $cb, $method = \"GET\", $inc_ns_api = true)\r\n\t{\r\n\t\t// Modify namespace to include API_VER\r\n\t\t$ns = $inc_ns_api ? $ns.'/'.self::API_VER : $ns;\r\n\r\n\t\t// Set arguments for anonymouse rest api callback\r\n\t\t$args = [\r\n\t\t\t\"ns\"\t\t\t=> $ns,\r\n\t\t\t\"route\"\t\t\t=> $route,\r\n\t\t\t\"component\" \t=> $component,\r\n\t\t\t\"callback\"\t\t=> $cb,\r\n\t\t\t\"method\"\t\t=> $method\r\n\t\t];\r\n\r\n\t\tself::$restArgs[] = $args;\r\n\t}`\r\n\r\nThen, the main class calls the function that loads the args, note that the args are 100% correct. I tried to spread the add_action() to multiple calls with hardcoded inputs, NOTHING!\r\n\r\n`\tstatic public function loadRoutes()\r\n\t{\r\n\t\tforeach (self::$restArgs as $args) {\r\n\t\t\t// Set current args\r\n\t\t\tself::$currArgs = $args;\r\n\r\n\t\t\t// Correct params\r\n\t\t\t// var_dump($args);\r\n\r\n\t\t\t// Define anonymouse rest api callback\r\n\t\t\t$restApiCallback = function () {\r\n\t\t\t    register_rest_route(self::$currArgs[\"ns\"], self::$currArgs[\"route\"], array(\r\n\t\t\t        'methods' \t=> self::$currArgs[\"method\"],\r\n\t\t\t        'callback' \t=> array(self::$currArgs[\"component\"], self::$currArgs[\"callback\"]),\r\n\t\t\t    ));\r\n\t\t\t};\r\n\r\n                         // Only last is successfully registered!!!!!!\r\n\t\t\tadd_action( 'rest_api_init', $restApiCallback );\r\n\t\t}\r\n\r\n\t\t// Clean registered routes\r\n\t\t$self::$restArgs = [];\r\n\t}`\r\n"},"comment":{"url":"https://api.github.com/repos/WP-API/WP-API/issues/comments/182596394","html_url":"https://github.com/WP-API/WP-API/issues/2263#issuecomment-182596394","issue_url":"https://api.github.com/repos/WP-API/WP-API/issues/2263","id":182596394,"user":{"login":"NizarBlond","id":2389428,"avatar_url":"https://avatars.githubusercontent.com/u/2389428?v=3","gravatar_id":"","url":"https://api.github.com/users/NizarBlond","html_url":"https://github.com/NizarBlond","followers_url":"https://api.github.com/users/NizarBlond/followers","following_url":"https://api.github.com/users/NizarBlond/following{/other_user}","gists_url":"https://api.github.com/users/NizarBlond/gists{/gist_id}","starred_url":"https://api.github.com/users/NizarBlond/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NizarBlond/subscriptions","organizations_url":"https://api.github.com/users/NizarBlond/orgs","repos_url":"https://api.github.com/users/NizarBlond/repos","events_url":"https://api.github.com/users/NizarBlond/events{/privacy}","received_events_url":"https://api.github.com/users/NizarBlond/received_events","type":"User","site_admin":false},"created_at":"2016-02-10T21:49:29Z","updated_at":"2016-02-10T21:49:29Z","body":"how do i pass with use? what do you mean?"}}