Поправить стандартный шаблон сообщения о комментариях
Есть стандартный шаблон
New comment on your post "TITLE" Author: USER (IP address: 255.255.255.255) Email: mail@mail.com URL: In reply to: Comment: ......
хочу добавить миниатюру поста в шаблон, как это сделать
(есть важные посты и не очень, некоторые нужно обязательно модерировать, некоторые самотеком)
результат
/****[000] comment_notification */ add_filter( 'comment_notification_headers', 'filter_function_name_889', 10, 2 ); function filter_function_name_889( $message_headers, $comment_id ){ $message_headers = str_replace("Content-Type: text/plain;", "Content-Type: text/html;", "$message_headers"); return $message_headers; } function wpd_comment_notification_text( $notify_message, $comment_id ){ // get the current comment and post data $comment = get_comment( $comment_id ); $post = get_post( $comment->comment_post_ID ); // don't modify trackbacks or pingbacks if( '' == $comment->comment_type ){ $thumb_url = get_the_post_thumbnail_url( $post->ID, 'thumbnail' ); $comment_author_domain = ''; if ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) { $comment_author_domain = gethostbyaddr( $comment->comment_author_IP ); } // build the new message text $notify_message = ' <img style="margin: 1px;padding: 5px;border: 3px solid #0000ff57;" src="'. $thumb_url .'" width=150px height=200px />' . "\r\n<br>"; $notify_message .= sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n<br>"; $notify_message .= sprintf( __('Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n<br>"; $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n<br>"; $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n<br>"; $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n<br><br>"; $notify_message .= __('You can see all comments on this post here: ') . "\r\n<br>"; $notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n<br><br>"; $notify_message .= sprintf( __('Permalink: %s'), get_comment_link( $comment_id ) ) . "\r\n<br>"; if ( user_can( $post->post_author, 'edit_comment', $comment_id ) ) { if ( EMPTY_TRASH_DAYS ) $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n<br>"; else $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n<br>"; $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n<br>"; } } // return the notification text return $notify_message; } add_filter( 'comment_notification_text', 'wpd_comment_notification_text', 20, 2 );
add_filter( 'comment_notification_text', 'wpd_comment_notification_text', 20, 2 );
Врезку нашел, а вот как картинку подключить не нашел, если html вставлять, тогда срабатывает фильтр и html отправляется в виде текста
Там используется
Content-Type: text/plain
тип письма, поэтому HTML туда вставить не получится просто на просто.Тебе нужно указать
Content-Type: text/html
переверстать весь шаблон на HTML и туда вставить миниатюру.Примерно так должен выглядеть запрос итоговый:
В описании хуков смотри и другие хуки, которые позволяют и другие данные изменить.
Спасибо, сработало
Далее только шаманить со стилем comment_notification_text осталось