Add “From” field into post content
-
Hi,
Thanks for this awesome plugin!
Is there a way to add “From” field (email address) into the post content? (e.g. in the beginning of the post / end of the post / its header)?
I created custom filter postie_filter_email as explained here http://postieplugin.com/extending/ and here http://postieplugin.com/postie_filter_email/ , but not sure what to do next.
Thank you in advance!
Andy
-
This topic was modified 9 years, 5 months ago by
andybarabash.
-
This topic was modified 9 years, 5 months ago by
-
I just went through something like this. I did it the very hard way and then, after some great feedback from the developer, did it a much easier way.
My advice is DON’T add the information until you get to the “postie_post_before” filter. The initial documentation I read only had one input to your filter: $post. So I did a lot of manipulation with “postie_post_pre” where the same documentation said you have access to $email. I pulled the “from” header information and then added it to the content of the email for later processing with my filter for “postie_post_before”. Somewhere along the way before it got to “postie_post_before”, the email addresses became HTML and was way more complicated to parse.
BUT as the developer pointed out, other (newer?) documentation for “postie_post_before” shows that you have access not only to $post, but to $email as well. So you can get the from information out of $headers[‘from’][‘mailbox’], $headers[‘from’][‘host’] and $headers[‘from’][‘personal’]. It’s very clean and can be added to $post[‘post_content’] wherever you want it.
This is the documentation that describes calling your filter with both parameters: http://postieplugin.com/postie_post_before/. Not sure how I missed it, but there it was.
Hope something in that helps.
What @dburk said.
Thanks for the info, but I’m afraid I’m still not getting this.
I created a a file called FilterPostie.php, and added the filter there:<?php function my_postie_post_function($post) { //do something here like update $post['post_content'] return $post; } add_filter('postie_post_before', 'my_postie_post_before', 10, 2); function my_postie_post_before($post, $headers) { //Do something return $post; } ?>Seems like now I just need to (1) introduce $email parameter somewhere and (2) add it to the post content (so that the first line of the post is “Sent from: $email”, and starting from the second line there goes email content). Am I right? What should I do next?
Sorry for all these questions, I’m not a programmer at all.-
This reply was modified 9 years, 5 months ago by
andybarabash.
I’m not sure what you’re doing with the my_postie_post_function, so we’ll ignore that. I hope this helps:
add_filter(‘postie_post_before’, ‘my_postie_post_before’, 10, 2);
function my_postie_post_before($post,$headers) {
$from = $headers[‘from’][‘mailbox’] . ‘@’ . $headers[‘from’][‘host’];
// you also might want to do something with $headers[‘from’][‘personal’];
$content = $post[‘post_content’];//This is where you would do all your manipulation
//One very simple example might be:
$newcontent = $fom . $content;//Then put it back in $post and you’re done
$post[‘post_content’] = $newcontent;
return $post;
}sorry, typo…
//One very simple example might be:
$newcontent = $from . $content; //’from’ (not ‘fom’)To add a little formatting you might do something like:
$newcontent = "<p>$from</p> $content";Thank you a lot! This really helps.
I’ve updated my filterPostie.php file (and Postie sees it in debug mode), but unfortunately nothing changes when it comes to publishing new posts from emails 🙁 So, a line with ‘From’ email does not show up.My filterPostie.php now looks like this:
<?php add_filter(‘postie_post_before’, ‘my_postie_post_before’, 10, 2); function my_postie_post_before($post,$headers) { $from = $headers[‘from’][‘mailbox’]; $content = $post[‘post_content’]; $newcontent = "<p>Sent from: $from <br></p> $content"; $post[‘post_content’] = $newcontent; return $post; } ?>Try:
$newcontent = “<p>Sent from: ” . $from . “<br></p>”. $content;
I modified the code, here’s how it looks now:
<?php add_filter(‘postie_post_before’, ‘my_postie_post_before’, 10, 2); function my_postie_post_before($post,$headers) { $from = $headers[‘from’][‘mailbox’] . "@" . $headers[‘from’][‘host’]; $content = $post[‘post_content’]; $newcontent = "<p>Sent from: " . $from . "<br></p>". $content; $post[‘post_content’] = $newcontent; return $post; } ?>But still doesn’t work. Nothing is shown in posts except for email content.
I’d add:
echo "in my_postie_post_before";
in my_postie_post_before then click the debug button and look for that in the output to make sure the filter is getting called.Checked this, the filter is being called:

please post the entire filterPostie.php, based on where the “in my_postie_post_before” showed up in the output something isn’t quite right.
Here’s what I have inside filterPostie.php
<?php add_filter(‘postie_post_before’, ‘my_postie_post_before’, 10, 2); function my_postie_post_before($post,$headers) { $from = $headers[‘from’][‘mailbox’] . "@" . $headers[‘from’][‘host’]; $content = $post[‘post_content’]; $newcontent = "<p>Sent from: " . $from . "<br></p>". $content; $post[‘post_content’] = $newcontent; return $post; } ?>I put echo “in my_postie_post_before”; instead of the function my_postie_post_before {…} part
-
This reply was modified 9 years, 5 months ago by
andybarabash.
I’m not sure what is happening, when I put this in my filterPostie.php it works.
<?php add_filter('postie_post_before', 'my_postie_post_before', 10, 2); function my_postie_post_before($post, $headers) { echo "my_postie_post_before"; $from = $headers['from']['mailbox'] . "@" . $headers['from']['host']; $content = $post['post_content']; $newcontent = "<p>Sent from: " . $from . "</p>" . $content; $post['post_content'] = $newcontent; return $post; } ?>I will say that I am running Postie 1.8.22 and you are running 1.7.32. Is there any reason you are on the older version?
-
This reply was modified 9 years, 5 months ago by
The topic ‘Add “From” field into post content’ is closed to new replies.