Filter: postie_post_before

This filter is called just before Postie saves the post.

At the point the filter is called a placeholder post has been created, but it doesn’t have any content. All the attachments have been uploaded and associated with this post.

Parameters:

  • $post
  • $headers (available starting at version 1.7.28)

The $post parameter is an array describing the post extracted from the email.

Essentially any field described here can show up.

You may modify any of the array elements.

The $headers parameter is an array of email headers. Note that this will vary depending on where the email came from.

You must return the $post array from your function. You may return null to prevent the post from being saved.

Example without headers

add_filter('postie_post_before', 'my_postie_post_before');

function my_postie_post_before($post) {
    //Do something
    return $post;
}

Example with headers

add_filter('postie_post_before', 'my_postie_post_before', 10, 2);

function my_postie_post_before($post, $headers) {
    //Do something
    return $post;
}

Post array

Array index Notes
post_author the WordPress user that is the author of the post.
post_date the localized date of the post.
post_date_gmt the GMT/UMT date of the post.
post_content the actual content of the post.
post_title the post title (email subject line).
post_name the sanitized post title.
post_excerpt the post excerpt.
ID the post id.
post_status the post status.
post_category an array of category IDs
ping_status
comment_status
post_type

Note that if Postie detects a email reply it will add a comment to the original post and the data in the array will be as follows:

comment_author
comment_post_ID
comment_author_email
comment_date
comment_date_gmt
comment_content
comment_author_url
comment_author_IP
comment_approved
comment_agent
comment_type
comment_parent
user_id

See this for more details.

Header array

The header variable is an associative array of mail headers, the keys being the lowercase header names. By default the values are a string, but the following headers are further parsed:

  • received: An array of the Recieved headers
  • to: An array of parsed addressees, each being an associative array in the format:
    • mailbox: The part before the @
    • host: The part after the @
    • personal: The addressee’s name optional
  • cc: An array of parsed addressees, in the same format as to
  • from: An associative array of the from address, in the same format as to
  • sender: An associative array of the sender address, in the same format as to
  • reply-to: An associative array of the address to reply to, in the same format as to
  • content-type: An associative array in the format:
    • value: The main header value
    • fields: An associative array of the ; separated key=value pairs after the main value
  • content-disposition: An associative array in the same format as content-type