I'm working on a plugin and I need to add an item (My page) to the user submenu:
I've added the link using a layer and there is no issue with displaying it The problem arises when clicking it.
My intention would be the link to direct the user to /user/$user_id/my_page in a similar way the wall redirects the user to /user/$user_id/wall. However, I've totally failed at this, mostly due to routing issues :/
Getting into the Core classes I found out that the wall item is based on a case statement in file qa-page-user.php (line 58). The case checks for the third part of the request and, if it is wall, it displays the wall template. This check is performed for wall, activity, questions and answers. Additionally, if it is null it defaults to the profile allowing the following url to be also valid /user/$user_id.
Now, if none of those values are in the url then the qa-page-not-found.php file is included. So it seems that if I wanted to add a page in the profile I have to modify that case statement which means modifying the core, which is not obviously advised. I would have expected an array with the current default url values so that the plugins can register the needed sub menu items dynamically and if there is no match then go to the not found page.
All alternatives I've found which I don't like (not quite tested or tried any of them ):
Modifying the qa-page-user.php file (which would mean the plugin will not work out of the box)
Add a new page outside of the user's menu (clearly not respecting the original requirement)
Access the main profile url but playing with a get parameter /user/$user_id?tab=my_page and juggling with the parts of the page in the main_parts method in the layer (so far the closest thing but implies removing elements from the profile so if a plugin adds elements to the core then my plugin will not remove them)
Modifying the qa-page-not-found.php to somehow handle those requests (same issue as the first item)
So it is possible but I wanted to find out the right way to do this. By the way, Onurb also did this http://peatarian.com/user/Bruno/gallery with a gallery an articles sub menu items. I wonder what approach he followed... but due to the 404 status code I see it is most likely the last one.