Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Display Wordpress comment_poster_ID in a Module WordPress

  • SOLVED

I would like a function programmed that would output the ID of the person that posted the comment which is being rated. This ID will be then used with the Comment Karma Module.

You can find Comment Karma at:
http://wealthynetizen.com/wordpress-plugin-comment-rating/

Answers (3)

2010-07-30

wjm answers:

Can we see the contents of your comments.php file
and if you can indicate WHERE you need to get the comment_poster_id,
it would be helpful.


badnews comments:

if($k_action == 'add') {
$rating = $row['ck_rating_up'] + 1 - $duplicated;
$direction = 'up';
$total = $total + 1 - $duplicated;
/* Modification to ck-processkarma.php */
if( function_exists('cp_alterPoints') && is_user_logged_in() ){
cp_alterPoints(cp_currentUser(), 1);
cp_log('Poll Vote', cp_currentUser(), 1, Polls);
}
}


I would like to somehow replace cp_currentUser() with comments_poster_id, within ck-processkarma.php.


wjm comments:

still i need to see the contents of your comments.php


badnews comments:

<?php
/**
* The template for displaying Comments.
*
* The area of the page that contains both current comments
* and the comment form. The actual display of comments is
* handled by a callback to twentyten_comment which is
* located in the functions.php file.
*
* @package WordPress
* @subpackage Twenty_Ten
* @since Twenty Ten 1.0
*/
?>

<div id="comments">
<?php if ( post_password_required() ) : ?>
<p class="nopassword"><?php _e( 'This post is password protected. Enter the password to view any comments.', 'twentyten' ); ?></p>
</div><!-- #comments -->
<?php
/* Stop the rest of comments.php from being processed,
* but don't kill the script entirely -- we still have
* to fully load the template.
*/
return;
endif;
?>

<?php
// You can start editing here -- including this comment!
?>

<?php if ( have_comments() ) : ?>
<h3 id="comments-title"><?php
printf( _n( 'One Response to %2$s', '%1$s Responses to %2$s', get_comments_number(), 'twentyten' ),
number_format_i18n( get_comments_number() ), '<em>' . get_the_title() . '</em>' );
?></h3>

<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through? ?>
<div class="navigation">
<div class="nav-previous"><?php previous_comments_link( __( '<span class="meta-nav">&larr;</span> Older Comments', 'twentyten' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( __( 'Newer Comments <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
</div> <!-- .navigation -->
<?php endif; // check for comment navigation ?>

<ol class="commentlist">
<?php
/* Loop through and list the comments. Tell wp_list_comments()
* to use twentyten_comment() to format the comments.
* If you want to overload this in a child theme then you can
* define twentyten_comment() and that will be used instead.
* See twentyten_comment() in twentyten/functions.php for more.
*/
wp_list_comments( array( 'callback' => 'twentyten_comment' ) );
?>
</ol>

<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through? ?>
<div class="navigation">
<div class="nav-previous"><?php previous_comments_link( __( '<span class="meta-nav">&larr;</span> Older Comments', 'twentyten' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( __( 'Newer Comments <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
</div><!-- .navigation -->
<?php endif; // check for comment navigation ?>

<?php else : // or, if we don't have comments:

/* If there are no comments and comments are closed,
* let's leave a little note, shall we?
*/
if ( ! comments_open() ) :
?>
<p class="nocomments"><?php _e( 'Comments are closed.', 'twentyten' ); ?></p>
<?php endif; // end ! comments_open() ?>

<?php endif; // end have_comments() ?>

<?php comment_form(); ?>

</div><!-- #comments -->


Sure its the default 2010 theme that is being used.


wjm comments:

Solved!

$comment_poster_ID = get_comment( $k_id )->user_id;
$total = $row['ck_rating_up'] - $row['ck_rating_down'];
if($k_action == 'add') {
$rating = $row['ck_rating_up'] + 1 - $duplicated;
$direction = 'up';
$total = $total + 1 - $duplicated;
/* Modification to ck-processkarma.php */
if( function_exists('cp_alterPoints') && is_user_logged_in() ){
cp_alterPoints( $comment_poster_ID, 1);
cp_log('Poll Vote', $comment_poster_ID, 1, Polls);
}
}
elseif($k_action == 'subtract')
{
$rating = $row['ck_rating_down'] + 1 - $duplicated;
$direction = 'down';
$total = $total - 1 + $duplicated;
} else {
die('error|Try again later'); //No action given.
}



you may also need to add your modification to the "subtract" conditional.


badnews comments:

Hey I am testing it now... I really hope it works :).


wjm comments:

it will
;^D


badnews comments:

Awesome!

Thank you so much.

2010-07-29

Deepak Thomas answers:

Hey, hi. I havent used CubePoints and am not sure what cp_currentUser() passes. I'm guessing it's the user ID. Then, the following code should work :


$whocommented= get_comment(get_comment_ID())->user_id;

/* Additional CubePoints integration */
if( function_exists('cp_alterPoints') && is_user_logged_in() ){
cp_alterPoints( $whocommented, 1);
cp_log('Poll Vote', $whocommented , 1, Polls);
}


This should be within the comment loop.


Deepak Thomas comments:

Hi there,
I havent used CubePoints and am not sure what cp_currentUser() returns. I'm guessing it's the userID. In that case, the following code should work just fine:


$whocommented = get_comment(get_comment_ID( ) )->user_id;
/* Additional CubePoints integration */
if( function_exists('cp_alterPoints') && is_user_logged_in( ) ){
cp_alterPoints($whocommented, 1);
cp_log('Poll Vote', $whocommented, 1, Polls);
}


PS: The code should be within the comment loop.


badnews comments:

Hey,

Thanks for the suggestion. You were correct in assuming that cp_currentUser() returns the ID for current logged in user. However, Nothing happens if I use this code. The code I am using (that worked in reverse) is being used with in ck-processkarma.php (so it is called when the vote is cast) as follows:

if($k_action == 'add') {
$rating = $row['ck_rating_up'] + 1 - $duplicated;
$direction = 'up';
$total = $total + 1 - $duplicated;

if( function_exists('cp_alterPoints') && is_user_logged_in() ){

cp_alterPoints(cp_currentUser(), 1);

cp_log('Poll Vote', cp_currentUser(), 1, Polls);

}

}


I don't know how to change cp_currentUser variable.


Deepak Thomas comments:

Hey.. Hi again,
While making the quick reply, I failed to notice that the code you gave wasn't actually within the comment loop.

The problem is that we need to pass the comment author's ID (Which will be available only within the loop) to a call outside the loop.

2010-07-29

Pippin Williamson answers:

Try replacing cp_currentUser() with comment_author()


badnews comments:

Unfortunately that doesn't work either.