Skip to content

Instantly share code, notes, and snippets.

@konradsroka
Last active March 5, 2018 04:58
Show Gist options
  • Save konradsroka/ae95dc2d05ff1121accb to your computer and use it in GitHub Desktop.
Save konradsroka/ae95dc2d05ff1121accb to your computer and use it in GitHub Desktop.
WordPress Plugins DWQA and myCred: Adding myCred points when comment on DWQA Question or Answer is added
// Note: Sadly you need to make one hack into the DWQA plugin as they didn't want to add a new do_action at this place.
// I was a bit disappointed with that answer, however you need to add the do_action into the DWQA plugin yourself.. :-/
// HOW TO MAKE THIS WORK:
// First add this whole PHP chunk to your theme's functions.php or into your custom plugin.
// Then copy this: do_action( 'kx_dwqa_add_comment' );
// Go to file dw-question-answer/inc/actions.php to the function dwqa_comment_action_add()
// and paste it right after the ob_end_clean(); - in the next line.
// That's it, save and test ;)
// Adding myCred points when comment on Q/A is added
if ( function_exists( 'mycred' ) && is_user_logged_in() ) :
add_action( 'kx_dwqa_add_comment', 'kx_add_points_for_dwqa_comments' );
function kx_add_points_for_dwqa_comments() {
$user_id = get_current_user_id();
// Init myCRED
$mycred = mycred();
// Add log entry and adjust the users balance
$mycred->add_creds(
'reference',
$user_id,
3,
'Beads for Approved Comment on Q/A'
);
}
endif;
@arize99
Copy link

arize99 commented Nov 21, 2017

do you need to have myCred plugin installed on the WP site as well before running the above code?

@FacePUSH
Copy link

FacePUSH commented Mar 5, 2018

Would it be possible to get some help setting this up. Having this working would absolutely make my week!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment