Category: How To

Action: postie_register_shortcode_pre

This action is called just before postie_post_before.

You use this action to register any Postie specific shortcodes.

<?php 
function my_postie_register_shortcode_pre() {
    //register any Postie shortcodes
    add_shortcode('myshortcode', 'my_shortcode');
}

add_action('postie_register_shortcode_pre', 'my_postie_register_shortcode_pre');

// works like a standard shortcode
function my_shortcode($att, $content = null) {
    global $postie_post; // the current post
    return '<p>My shortcode</p>';
}
?>

Filter: postie_parent_post

This filter is called to determine if there should be a parent post.
Parameters:
  • $parentid – an integer which is the post ID that Postie thinks should be the parent. If Postie doesn’t think there is a parent the value will be NULL.
  • $email – the parsed email
add_filter('postie_parent_post', 'my_postie_parent_post', 10, 2);

function my_postie_parent_post($parentid, $email) {
    return $parentid; 
}

Available starting in version 1.9.27

Filter: postie_include_attachment

This filter is called before Postie saves the attachment to media library. Typically you would use this filter if you wanted to prevent Postie from processing certain files. I.e. all non-image files or you could exclude all executable files or use your own whitelist or exclude all files.
Parameters:
  • $attachment – an array of information about the attachment
    • filename – the name of the file as specified in the email.
    • mimetype – the mimetype of the file.
    • data – the content of the file.
add_filter('postie_include_attachment', 'my_postie_include_attachment', 10, 2);

function my_postie_include_attachment($include, $attachment) {
    return false; //don't include any attachments
}

 

Action: postie_file_added_pre

This action is called after Postie successfully extracts an email attachment and before it adds it as a media item to the post. At the point it is called there is only a placeholder post, e.g. the content and metadata is not set yet.

add_action('postie_file_added_pre', 'my_fileaddedpre', 10, 2);

function my_fileaddedpre($postid, $file_array) {
    error_log("file name: {$file_array['name']}");
    error_log("file type: {$file_array['type']}");
    error_log("file path: {$file_array['tmp_name']}");
    error_log("file size: {$file_array['size']}");
}

Previous versions

You can download the last 35 releases of Postie here in case you need to roll back for some reason.

Current Version

1.9.53 - download

Other Versions

Filter: postie_category

This filter is called after the category is detected in the subject line. You could use this filter to create a missing category or force it to be one of a list of approved categories. Note this filter will be called multiple times if there are multiple categories in the subject line.

You should return a string that is a valid category or taxonomy term. If the returned value is not a valid category or taxonomy term then the unknown category will remain in the subject line.

Parameters:
  • $category_name – the category extracted from the subject line. Note this could be a category ID. The delimiters are not included e.g. for the subject line “[mycategory] subject line” this parameter would be “mycategory”
  • $match_short_category – a boolean indicating if Postie will try to look up the category using “starts with” logic. Controlled by the “Match short category” setting.
  • $default – the default category as defined by the “Default category” setting or the results of the postie_category_default filter.
add_filter('postie_category', 'my_postie_category', 10, 3);

function my_postie_category($category_name, $match_short_category, $default) {
 return ''; //don't allow user to set category
}

Filter: postie_bare_link

This filter is called for each bare link Postie finds in your message. Bare links are plain URLs without any markup. I.e. “http://www.example.com” is a bare link. “Not a bare link” is not a bare link. Note some email clients will transform bare links into non-bare links especially if you are using rich text/html. Generally if you want to take advantage of this filter consistently you will want to set Preferred Text Type to Plain.

Parameters:

  • $html – the html that will be inserted into the post.
  • $URL – the original URL (bare link).
  • $oembed – whether WordPress thinks this bare link can be handled by the “Easy Embed” feature. See https://codex.wordpress.org/Embeds

You must return a string that will be placed at the spot where the bare URL was found.

Example

add_filter('postie_bare_link', 'my_postie_bare_link', 10, 3);

function my_postie_bare_link($html, $url, $oembed) {
    if ($oembed)
        return htmlspecialchars($url);
    else
        return "<div class='mylinkclass'>$html</div>";
}

action: postie_raw

This action is called when Postie retrieves an email from the server.

Parameters:

  • $rawEmail

The $rawEmail parameter the email as retrieved from the server. Note you can’t make changes to the email at this point.

Example

add_action('postie_raw', 'my_postie_raw');

function my_postie_raw($rawemail) {
    //Do something
}

 

Filter: postie_place_media_after

This filter is called after the image/audio/video/attachment template has been filled out and the “Image Location” setting is “After” and gives you the opportunity to change the markup referring to the media.

Parameters:
  • $html – the html fragment that will replace the placeholder. This html is based on the template specified in the settings for the file type.
  • $media_id –  the ID of the media being used to replace the placeholder.
add_filter('postie_place_media_after', 'my_postie_place_media_after', 10, 2);

function my_postie_place_media_after($html, $media_id) {
    $type = get_post_mime_type($media_id);
    if ($type == 'image/jpeg') {
        $html .= '<p>This is copyright by me</p>';
    }
    return $html;
}

Filter: postie_place_media_before

This filter is called after the image/audio/video/attachment template has been filled out and the “Image Location” setting is “Before” and gives you the opportunity to change the markup referring to the media.

Parameters:
  • $html – the html fragment that will replace the placeholder. This html is based on the template specified in the settings for the file type.
  • $media_id –  the ID of the media being used to replace the placeholder.
add_filter('postie_place_media_before', 'my_postie_place_media_before', 10, 2);

function my_postie_place_media_before($html, $media_id) {
    $type = get_post_mime_type($media_id);
    if ($type == 'image/jpeg') {
        $html .= '<p>This is copyright by me</p>';
    }
    return $html;
}