logo

$10
Display Wordpress comment_poster_ID in a Module

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/

badnews | 07/29/10 at 4:22am | Edit


(3) Possible Answers Submitted...

  • avatar
    Last edited:
    07/29/10
    5:16am
    Deepak Thomas says:

    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.

    • 07/29/10 5:26am

      Deepak Thomas says:

      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.

    • 07/29/10 10:52am

      badnews says:

      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.

    • 07/29/10 1:49pm

      Deepak Thomas says:

      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.

  • avatar
    Last edited:
    07/29/10
    11:50am
    Pippin Williamson says:

    Try replacing

    cp_currentUser()
    with
    comment_author()

    • 07/29/10 11:53am

      badnews says:

      Unfortunately that doesn't work either.

  • avatar
    Last edited:
    07/30/10
    5:10pm
    wjm says:

    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.

    Previous versions of this answer: 07/30/10 at 11:43am

    • 07/30/10 2:10pm

      badnews says:

      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.

    • 07/30/10 2:13pm

      wjm says:

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

    • 07/30/10 2:16pm

      badnews says:

      <?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() ), '' . get_the_title() . '' );
      ?></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.

    • 07/30/10 4:56pm

      wjm says:

      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.

    • 07/30/10 5:01pm

      badnews says:

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

    • 07/30/10 5:03pm

      wjm says:

      it will
      ;^D

    • 07/30/10 5:06pm

      badnews says:

      Awesome!

      Thank you so much.

This question has expired.





Current status of this question: Completed