Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
in Q2A Core by
edited by

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 smiley):

  1. Modifying the qa-page-user.php file (which would mean the plugin will not work out of the box)
  2. Add a new page outside of the user's menu (clearly not respecting the original requirement)
  3. 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)
  4. 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.



Q2A version: 1.6.2

1 Answer

+1 vote
edited by

Have you already had a look at the SubNavi Maker plugin  ? Maybe in its code you could find something interesting....(or  you could use it directly as a dependency of your plugin)  smiley

Thanks. However I don't think this would do it. Mostly because this plugin has the logic to add the link (I have already done that) but I need the logic to handle the link. As I explained in the question, the users section will block any request to a non-core page and I need to dodge that block somehow.

BTW, the plugin didn't actually work out of the box in 1.6.2. A quick look at the code made me blame this line "if ($request == $url[0])" which was comparing "http://localhost/webs/mysite/account" against "account". You might want to use qa_request() and/or qa_request_part(x) :)
The Subnavi Maker plugin supported handle name in URL at V1.1 (2013/11). I updated the old capture of two pages.


In addition, you can use "@EVAL" in "Subnavi list" option. This is a slightly difficult feature for programmers...

When you expect the URL constitution such as the lower site, it will be necessary to remodel the core of Q2A. However, if you use URL parameter, you can come true without remodeling Q2A core. Badge plugin of Noah realizes this well.

Hi sama55, thanks for the comment. So you'd go for option #3 too (it has 2 votes so far). Although it is the best way to go, it is still a workaround, as it accesses the profile URL (which allows it to overcome the case statement I mentioned in my question) and then removes the whole output that the Q2A core generated and then adds the badges.

Although this does not modify the core it does modify its output so it can still result in incompatibilities in future Q2A versions and/or if new plugins are added that also modify the profile section.
Programs always change. There is no program to be able to guarantee 100% of future compatibility. The best at the present may not be the best anymore tomorrow. Because you have accurate analytical ability, I think that you choose the measures that you think to be more better in the range of given condition. By the way, I hear that the processing about user information is improved in 1.6.3. The details is not yet clear ...