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

I am finding it necessary to modify some functions within the Q2A engine for various reasons.  I would like to at least centralize these changes somehow so that I don't have to comb through all the files when the next version is released.

Is there any way to do this?

If you're wondering what I'm changing...  here are a few examples:

  • changing emails to print out user's names (from my DB) instead of handles (which are unique but not so pretty)
  • adding options a_meta_order and q_meta_order which allow for different meta structures for questions and answers
  • adding a $min_qs_to_show_category option so that I can predefine a bunch of categories but still only show categories that have at least 1 question
  • modified qa-include/qa-index.php to create an "inline" theme so that I can display a user's Q&A activity within existing profiles

There are plenty more.  Most of them are relatively minor changes designed to make Q2A play nicely with me site, but a lot of files have been tweaked at this point. 

2 Answers

+2 votes
by

Changing the emails is possible by editing a particular file, possibly qa-util-emailer.php. I can't find documentation about it on this site but it's briefly mentioned at the bottom of this page.

I'm not sure what your last bullet point is doing but you can change a lot within custom themes using $this->request. If not that maybe a widget plugin?

For everything else, what I do is add special comments at every place I make a change that includes my initials, for example:

    /** SV: notifications off by default */

Then when I upgrade, I rename the old Q2A installation folder and copy the new one into its place, so I start with a blank canvas. Then find all the bits of code I modified in the old codebase and copy the changes across to the new one. On Linux I use this command to find what needs changing:

    grep -R "/\*\* SV:" .

On Windows you can use Notepad++ or another method. It may be a little time-consuming if you made a lot of changes but it works well for me.

by
Thanks -- this is what I have been doing, more or less, but I've got about 30 files changed now and though most changes are minor, I am not looking forward to the migration.
by
It's also worth asking here in future if certain changes could be done with plugins or themes. I always find when upgrading that many of my core changes can be done outside the core.
0 votes
by

Looking at your list, to follow up on what Scott says, functions like adding things to user profiles doesn't require hacking the code... see the badges plugin, for example - I've even added a submittable form to the user profile page. 

Adding options is allowed by qa_opt('name',$value), but I'm not sure exactly what you're doing with the options - most anything can be done with layers.

The only point I can see problematic is the first, as Scott notes.  This would be solved by hooks, as pointed out here:

http://www.question2answer.org/qa/8373/would-it-be-difficult-to-implement-function-hooks

Apart from that, I guess it would be ideal if functions were redefinable (something that is normally not possible with php).  The wordpress page on child themes suggests that if every core function be declared as follows:

if (!function_exists('theme_special_nav')) {
    function theme_special_nav() {
        //  Do something.
    }
}

then it would be possible to allow plugins to predefine them, and thus override the core functions.  

This would make customization really easy.   You could then just define qa_send_notification in your plugin and change it to something like:

			$subs['^handle']=qa_get_username_from_handle($handle);

Edit: Wordpress actually has a list of "pluggable functions" here:

http://codex.wordpress.org/Pluggable_Functions

That would be something to ask Gideon really nicely to implement :)  I'll start my 1.5 list now.
...