Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have function in my plugin that is:

add_filter('comment_text', 'commentimage_comment_text');
function commentimage_comment_text($comment = '') { 
  $options = get_option('commentimage');
  $id = get_comment_ID();

  $images = $options['images'];
  if (!isset($images) || !is_numeric($images)) $images = 1;
    $url = get_option('siteurl');
    for ($i=0; $i<$images; $i++) {
      if (file_exists(ABSPATH . 'wp-content/comment-image/' . $id . ($i==0?'':('-'.$i)) . '-tn.jpg')) {
         $comment .= '<p><a href="' . $url . '/wp-content/comment-image/' . commentimage_find_original($id, $i) . '"><img src="' . $url . '/wp-content/comment-image/' .    $id . ($i==0?'':('-'.$i)) . '-tn.jpg"/></a></p>';
      }
    }
  return $comment;
}

Now it is showing a successful image uploaded by my viewers. I want my viewers to have the option of rating them, so for that I write in my plugin just below the above line the following code:

 add_filter('comment_text', 'commentimage_comment_text2');
 function commentimage_comment_text2()
 {
   $rtt= "<br>Rating";
   return $rtt;
 }

Then my pictures are gone and it shows text rating - I will change the text rating to my desired needs once I get the answer on how to overcome over writing.

share|improve this question

1 Answer 1

up vote 10 down vote accepted

It looks like you are overwriting the comment text with your commentimage_comment_text2 filter, try this to append the ratings text:

add_filter( 'comment_text', 'commentimage_comment_text2' );
function commentimage_comment_text2( $comment ){
    $rtt = "<br>Rating";

    return $comment.$rtt;
}

ps: you forgot the $comment input parameter.

Here is a poor man's skematic picture of the filter flow in WordPress ;-)

poor man's skematic image of the filter flow in WordPress

The filter icon was taken from here.

In your case the filter's name is comment_text and your two callbacks are commentimage_comment_text and commentimage_comment_text2 with priority 10 (the default).

You can view all the callbacks for this filter with this code snippet:

add_action('wp_footer',function(){
        global $wp_filter;
        printf('<pre>%s</pre>',print_r( $wp_filter['comment_text'],true));
});

On my install I get the following output (in my theme's footer part) of all these callbacks with the corresponding assigned pirorities.

I added your two callbacks commentimage_comment_text and commentimage_comment_text2 so you can see them too:

Array
(
    [9] => Array
        (
            [make_clickable] => Array
                (
                    [function] => make_clickable
                    [accepted_args] => 1
                )
        )
    [10] => Array
        (
            [wptexturize] => Array
                (
                    [function] => wptexturize
                    [accepted_args] => 1
                )
            [convert_chars] => Array
                (
                    [function] => convert_chars
                    [accepted_args] => 1
                )
            [commentimage_comment_text] => Array
                (
                    [function] => commentimage_comment_text
                    [accepted_args] => 1
                )
            [commentimage_comment_text2] => Array
                (
                    [function] => commentimage_comment_text2
                    [accepted_args] => 1
                )
        )
    [20] => Array
        (
            [convert_smilies] => Array
                (
                    [function] => convert_smilies
                    [accepted_args] => 1
                )
        )
    [25] => Array
        (
            [force_balance_tags] => Array
                (
                    [function] => force_balance_tags
                    [accepted_args] => 1
                )
        )
    [30] => Array
        (
            [wpautop] => Array
                (
                    [function] => wpautop
                    [accepted_args] => 1
                )
        )
    [31] => Array
        (
            [capital_P_dangit] => Array
                (
                    [function] => capital_P_dangit
                    [accepted_args] => 1
                )
        )
)
share|improve this answer
2  
+1, but could you flesh out an explanation for why one callback is overwriting the other (i.e. a bit of explanation for how the filter callback works)? –  Chip Bennett Jun 3 '13 at 13:57
    
thanks, I tried to draw a picture but I'm not sure if it helps :-) –  birgire Jun 3 '13 at 15:26
    
Wish I could give another +1. :) –  Chip Bennett Jun 3 '13 at 15:47
    
Great and detailed explaination just wow ! .... Sir can I ask you another question its real important ? –  Kelly James Jun 4 '13 at 4:59
    
thanks, sure if it's related to the above question, otherwise it might be better to ask a new question. –  birgire Jun 4 '13 at 9:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.