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.

my client in his template is using <?php comment_author_IP(); ?> to display IP's of comment authors. Recently he came to me with idea of limiting whole number to several characters. Final result should be something simillar to:

192.168...

How can i achieve it? I've tried with jquery but without success. It looked like it was not responding to the jquery code..

thank you!

share|improve this question

1 Answer 1

up vote 4 down vote accepted

You can filter 'get_comment_author_IP':

add_filter( 'get_comment_author_IP', 'wpse_77254_trim_comment_ip' );

function wpse_77254_trim_comment_ip( $ip )
{
    return implode( '.', array_slice(explode( '.', $ip ), 2) ) . '…';
}

Note this will fail with IPv6 addresses.

share|improve this answer
    
Brilliaaantttt! Thank you Toscho! –  Paweł Skaba Dec 25 '12 at 22:02

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.