Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
876 views
in Q2A Core by
edited by
I am looking at creating a custom page (with PHP code) based on the related answer.

But there is a problem - because you're calling a page that Q2A doesn't think exists, it returns a 404 error (although the page displays fine).

Do we need to add something to the core to overcome this, or can we cancel the 404 header in the "main()" function?

EDIT: another issue: I'm following some code posted in other questions to obtain the current user. I have:
    $qa_login_user = qa_get_logged_in_user($qa_db);

But I just get "Fatal error:  Call to undefined function qa_get_logged_in_user() ..."
I added an include for 'qa-app-user.php' at the top of the script but I still get the same error. Full code:

    require_once 'qa-include/qa-app-users.php';
    global $qa_db;
    $qa_login_user = qa_get_logged_in_user($qa_db);
related to an answer for: Custom page with custom php page

1 Answer

+1 vote
by
 
Best answer
Assuming it's a page with a specific URL fragment, just add a custom page via the 'Pages' panel of the 'Admin' interface with the same URL fragment. That way Q2A's app layer will think the page exists and not included the HTTP 404 header. You can then still override the actual content output for the page in an advanced theme.

Or if you want to override this in general, remove the following line from function qa_home_load_ifcategory(...) in qa-page-home.php:

header('HTTP/1.0 404 Not Found');

As for the other issue, the functions for getting info about the current logged in user changed in version 1.2. See the set of functions whose names start with qa_get_logged_in_... in the qa-app-users.php file.
by
I already added a 'link' in the admin, do you mean I should add a page (ie the one with HTML content)?

As for the other problem, the function qa_get_logged_in_user exists in qa-app-users.php, no idea why calling it would fail like it does.
by
Yes, it needs to be a page rather than a link.

If you're using the 1.2.x source, the function qa_get_logged_in_user(...) is *called* in qa-app-users, but this is only in the part used for single-sign on.
by
My bad, I was looking at the qa-app-users.php from the old version! I can see the functions you're talking about now, cheers.
...