Help with extending QA_AJAX class?

What I'm trying to do is extend the core class QA_AJAX so that in the 'vote' function rather than calling the function 'the_question_voting' it uses a new, slightly modified one.

In my theme's functions.php I've added the following code:

class QA_AJAX_new extends QA_AJAX {
	function vote() {
		global $_qa_votes;
		$_qa_votes->handle_voting();
		$id = $_POST['post_id'];
		$post_type = get_post_type( $id );
		if ( 'question' == $post_type )
			the_question_voting_new( $id );
		elseif ( 'answer' == $post_type )
			the_answer_voting( $id );
		else
			die( -1 );
		die;
	}
}

This is essentially exactly the same as the code in the core file, but it calls 'the_question_voting_new' instead of 'the_question_voting' (on line 8 above).

I then created my new function (again in functions.php) called 'the_question_voting_new'.

The problem is that this doesn't appear to have made any difference. When clicking on the vote button it's still using the old function 'the_question_voting'.

I'm not a developer, so I may have got completely the wrong idea about how to extend a php class, but I'm sure I've done this in the past and it's worked.

Any suggestions?

  • Philip John
    • DEV MAN’s Apprentice

    Hiya!

    This isn't something we can generally support as it's custom coding, though I'll ask if the developer can spare 5 minutes to provide some guidance.

    Either way, if you're not an experienced coder I'd recommend hiring a developer to do this for you.

    Phil

  • mattbailey
    • Design Lord, Child of Thor

    Thanks Phil. I'm a fairly experienced front-end coder who doesn't mind hacking up a bit of php.

    Like I said, I've used this method to extend classes in the past, but in this case it's not working and I'm wondering what I'm missing.

    Essentially all I want to do is use my own customised function for 'the_question_voting'. I would much rather override the class and call this new function that hack the core code.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.