Guest comments not affecting comment points?
-
On my site, my authors mostly get comments by guests (none-members). It seems that when a guest posts a comment, the balance does not change at all for the post author (content author).
Maybe this is a bug? If not, is there a solution for this?
Thank you!
-
As it stands right now, users must be logged in to get points for comments and the same goes for the authors as myCRED saves the commenters ID as a reference to prevent duplicate points for the same comment.
I will look into changing this somehow in future versions but till then your only option is to hook into the ‘transition_comment_status’ action and/or ‘comment_post’ action and award points to the author if the commenter is not a member.
I’m in desperate need of a fix for this too.
Gabriel can you show us how to hook into these to award points to author if the commenter is not a user. I’m not as knowledgable as you all are with programming.
Here is a basic example that awards 1 point for each approved comment to the content author. You can customize the amount and log template to your liking.
add_action( 'transition_comment_status', array( $this, 'comment_transitions' ), 10, 3 ); function award_points_for_guest_comments( $new_status, $old_status, $comment ) { // Look for approved comments if ( $new_status != 'approved' ) return; // Grab the comment object in case it is not there if ( !is_object( $comment ) ) $comment = get_comment( $comment ); // Ignore Pingbacks or Trackbacks if ( !empty( $comment->comment_type ) ) return; // Get post author $post = get_post( (int) $comment->comment_post_ID ); $post_author = $post->post_author; // Check if the post author should be excluded if ( mycred_exclude_user( $post_author ) === true ) return; // Award points to author mycred_add( 'new_comment', // reference $post_author, // who to get points 1, // number of points to award '%plural% for new comment on post', // log template to use $comment->comment_ID, // save comment id as reference id array( 'ref_type' => 'comment' ) // enable support for comment related template tags ); }
Wow I’m going to try this out. Cheers for the added comments!
How do I support this plugin? Do you have a paypal donation or similar setup?
Hey Lars.
You can either donate cups of coffee or visit the store.
Thank you in advanced.This plugin saves me thousands of pounds, so yes, I will support it and so should many others.
I added the code in my function.php file but it did not function. Made a guest comment but nothing was updated in the logs. Did this work for you (using 1.3)?
And when permanently deleting a comment, these warnings are shown:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in /public_html/wp-includes/plugin.php on line 406
Warning: Cannot modify header information – headers already sent by (output started at /public_html/wp-includes/plugin.php:406) in /public_html/wp-includes/class-wp-ajax-response.php on line 129
Upps, I see I was a bit to quick in copy pasting. The issue is the hook is incorrect. It should be:
add_action( 'transition_comment_status', 'award_points_for_guest_comments', 10, 3 );
Added your fix but is still not working. Posted guest comment and no update in the logs. Maybe I am doing something wrong?
This is the complete code that I use:
add_action( 'transition_comment_status', 'award_points_for_guest_comments', 10, 3 ); function award_points_for_guest_comments( $new_status, $old_status, $comment ) { // Look for approved comments if ( $new_status != 'approved' ) return; // Grab the comment object in case it is not there if ( !is_object( $comment ) ) $comment = get_comment( $comment ); // Ignore Pingbacks or Trackbacks if ( !empty( $comment->comment_type ) ) return; // Get post author $post = get_post( (int) $comment->comment_post_ID ); $post_author = $post->post_author; // Check if the post author should be excluded if ( mycred_exclude_user( $post_author ) === true ) return; // Award points to author mycred_add( 'new_comment', // reference $post_author, // who to get points 1, // number of points to award 'Guest comment on <a href=%c_post_url%>%c_post_title%</a>', // log template to use $comment->comment_ID, // save comment id as reference id array( 'ref_type' => 'comment' ) // enable support for comment related template tags ); }
A few things to try:
1. Enable WP_DEBUG in your wp-config.php file when you approve a comment to see if you get any error messages.
2. Make sure the post author is not set to be excluded from using myCREDI enabled WP_DEBUG and it did not show errors, only these warnings:
Warning: session_start(): Cannot send session cache limiter – headers already sent (output started at public_html/wp-content/plugins/w3-total-cache/lib/W3/Cache/Memcached.php:15) in public_html/wp-content/plugins/myqaptcha/myQaptcha.php on line 44
Warning: Cannot modify header information – headers already sent by (output started at public_html/wp-content/plugins/w3-total-cache/lib/W3/Cache/Memcached.php:15) in public_html/wp-includes/comment.php on line 621
Warning: Cannot modify header information – headers already sent by (output started at public_html/wp-content/plugins/w3-total-cache/lib/W3/Cache/Memcached.php:15) in public_html/wp-includes/comment.php on line 622
Warning: Cannot modify header information – headers already sent by (output started at public_html/wp-content/plugins/w3-total-cache/lib/W3/Cache/Memcached.php:15) in public_html/wp-includes/comment.php on line 623
Warning: Cannot modify header information – headers already sent by (output started at public_html/wp-content/plugins/w3-total-cache/lib/W3/Cache/Memcached.php:15) in public_html/wp-includes/pluggable.php on line 875
About your second step, I’m not sure what you mean. I have not excluded any users from using myCRED. And I tried guest commenting on more than one post.
Did that code work on your test environment?
Cheers for the support!
I think the issue is that the above code only works if you have setup to approve comments. If a comment is approved without moderation you would need to add more.
Try this (replacing your old code):
if ( function_exists( 'mycred_add' ) ) { add_action( 'comment_post', 'award_new_guest_comments', 10, 2 ); function award_new_guest_comments( $comment_id, $comment_status ) { if ( $comment_status == '1' ) award_points_for_guest_comments( 'approved', '', $comment_id ); } add_action( 'transition_comment_status', 'award_points_for_guest_comments', 10, 3 ); function award_points_for_guest_comments( $new_status, $old_status, $comment ) { // Look for approved comments if ( $new_status != 'approved' ) return; // Grab the comment object in case it is not there if ( !is_object( $comment ) ) $comment = get_comment( $comment ); // Ignore Pingbacks or Trackbacks if ( !empty( $comment->comment_type ) ) return; // Get post author $post = get_post( (int) $comment->comment_post_ID ); $post_author = $post->post_author; // Check if the post author should be excluded if ( mycred_exclude_user( $post_author ) === true ) return; // Award points to author mycred_add( 'new_comment', // reference $post_author, // who to get points 1, // number of points to award 'Guest comment on <a href=%c_post_url%>%c_post_title%</a>', // log template to use $comment->comment_ID, // save comment id as reference id array( 'ref_type' => 'comment' ) // enable support for comment related template tags ); } }
THe above code will work both with non-moderated comments and if you manually approve a comment.
And it did! You are a star! Cheers for your hard work, it doesn’t go unnoticed.
Awesome! Ill mark this as resolved.
Let me know if you have any further issues.
- The topic ‘Guest comments not affecting comment points?’ is closed to new replies.