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.

Basically I need to remove or comment our lines 1114 - 1116 in pluggable.php, and edit line 1113

These are the lines

$notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
$notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
$notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n";
$notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n";

They are all part of function - wp_notify_postauthor

I can replace the whole thing by creating a plugin (which is what I've done) - but is there a way to just change those affected lines - without replacing the whole function?

Thanks

share|improve this question

1 Answer 1

There is a hook that should let you alter that data-- comment_notification_text.

add_action(
  'comment_notification_text',
  function($notify_message,$comment_id) {
    var_dump($notify_message,$comment_id);
    die;
  },
  10,2
);

You could parse that $notify_message string and remove the parts you don't want.

add_filter(
  'comment_notification_text',
  function($notify_message) {
    $notify_message = explode("\n",$notify_message);
    foreach ($notify_message as $k => $line) {
      $header = trim(substr($line,0,strpos($line,':')));
      switch ($header) {
        case 'E-mail':
        case 'URL' :
        case 'Whois':
          unset($notify_message[$k]);
        break;
        case 'Author' :
          $pat = '([^(]+)\(.*$';
          $notify_message[$k] = trim(preg_replace('|'.$pat.'|','$1',$line));
        break;
      }
    }
    $notify_message = implode("\n",$notify_message);
    return $notify_message;
  }
);

I think that accomplishes what you were going for.

share|improve this answer
    
Wow - this looks good... I guess I'd dump this in my functions php? –  JorgeLuisBorges Feb 25 at 18:09
    
I should also clarify that I'm trying to remove any reference to the comment authors email or ip address - so for the author line its just the second two values I'm trying to drop (ip address and domain) –  JorgeLuisBorges Feb 25 at 18:10
    
That should work from functions.php, a plugin, or a mu-plugin file. –  s_ha_dum Feb 25 at 18:12
    
It won't work with translation though. You will need to work that out yourself. –  s_ha_dum Feb 25 at 18:12

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.