Help extending class used in Wordpress plugin
First, a proviso - I'm a designer not a dev, so please be gentle ;)
I'm trying to tweak a Wordpress plugin by extending a class. In the class in a bit of conditional if/elseif-ing the code calls one of two functions. Instead of these functions I've want to call two new ones (effectively the same functions as the old ones but again, slightly tweaked).
I've done this successfully before by doing this:
class MY_CLASS extends MY_NEW_CLASS { ...
Then I change the code in the class and away we go. However, in this case it doesn't appear to be working?
Below I've pasted the class code that I've put into my functions.php file:
class QA_AJAX_new extends QA_AJAX {
function init() {
add_action( 'wp_ajax_qa_vote', array( __CLASS__, 'vote' ) );
add_action( 'wp_ajax_qa_accept', array( __CLASS__, 'accept' ) );
}
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_new( $id );
else
die( -1 );
die;
}
function accept() {
global $_qa_votes;
$_qa_votes->handle_accepting();
$id = $_POST['answer_id'];
the_answer_accepted( $id );
die;
}
}
QA_AJAX_new::init();
About half way down you can see the two new functions I want the class to use, the_question_voting_new
and the_answer_voting_new
. I've also changed the code at the end that now says QA_AJAX_new::init();
- I'm not sure if I'm supposed to do that, but I've tried it both ways and neither makes a difference.
I'm clearly doing something wrong (or trying to do something that's not possible), something a dev would spot instantly, but my poor designer brain doesn'开发者_运维技巧t know enough about php to figure it out.
Thanks.
My first thought is that Init
isn't static so you can't call it using QA_AJAX_new::init();
. In the script that the form posts to try :
$qa_ajax = new QA_AJAX_new();
$qa_ajax->init();
You might look into Object Inheritance, which seems to be the problem.
Here's a couple of other things you might try...
- In wp-config.php, set WP_DEBUG to true:
define('WP_DEBUG', true);
- Make sure the PHP
display_errors
directive is set to 1, which you should be able to addini_set('display_errors', 1);
to your wp_config.php file.
This will help see any errors that may be being triggered and suppressed.
One of the most common things I've found as well as other WP developers is that so many plugin/theme authors will not set WP_DEBUG to true while writing their code and many times you'll find your error in the messages.
精彩评论