| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* WARNING - WARNING - WARNING |
| 5 |
* Do not put any custom filter code in the Postie directory. The standard WordPress |
| 6 |
* upgrade process will delete your code. |
| 7 |
* |
| 8 |
* Instead copy filterPostie.php.sample to the wp-content directory and rename it |
| 9 |
* to filterPostie.php and edit to your hearts content. |
| 10 |
* |
| 11 |
* Another option is to create your own plugin or add this code to your theme. |
| 12 |
*/ |
| 13 |
|
| 14 |
/* |
| 15 |
* Any filter function you write should accept one argument, which is the post |
| 16 |
array, which contains the following fields: |
| 17 |
'post_author' |
| 18 |
'comment_author' |
| 19 |
'comment_author_url' |
| 20 |
'user_ID' |
| 21 |
'email_author' |
| 22 |
'post_date' |
| 23 |
'post_date_gmt' |
| 24 |
'post_content' |
| 25 |
'post_title' |
| 26 |
'post_modified' |
| 27 |
'post_modified_gmt' |
| 28 |
'ping_status' |
| 29 |
'post_category' |
| 30 |
'tags_input' |
| 31 |
'comment_status' |
| 32 |
'post_name' |
| 33 |
'post_excerpt' |
| 34 |
'ID' |
| 35 |
'customImages' |
| 36 |
'post_status' |
| 37 |
|
| 38 |
Your function can modify any of these fields. It should then return the array |
| 39 |
back. If you return null then the post will not be created. |
| 40 |
*/ |
| 41 |
|
| 42 |
add_filter('postie_post_before', 'filter_title'); |
| 43 |
add_filter('postie_post_before', 'filter_content'); |
| 44 |
add_filter('postie_post_before', 'add_custom_field'); |
| 45 |
add_filter('postie_post_before', 'auto_tag'); |
| 46 |
|
| 47 |
add_filter('postie_filter_email', 'change_email'); |
| 48 |
|
| 49 |
function filter_content($post) { |
| 50 |
//this function prepends a link to bookmark the category of the post |
| 51 |
$this_cat = get_the_category($post['ID']); |
| 52 |
//var_dump($this_cat); |
| 53 |
$link = '<a href="' . get_category_link($this_cat[0]->term_id) . |
| 54 |
'">Bookmark this category</a>' . "\n"; |
| 55 |
$post['post_content'] = $link . $post['post_content']; |
| 56 |
return $post; |
| 57 |
} |
| 58 |
|
| 59 |
function filter_title($post) { |
| 60 |
//this function appends "(via postie)" to the title (subject) |
| 61 |
$post['post_title'] = $post['post_title'] . ' (via postie)'; |
| 62 |
return $post; |
| 63 |
} |
| 64 |
|
| 65 |
function auto_tag($post) { |
| 66 |
// this function automatically inserts tags for a post |
| 67 |
$my_tags = array('cooking', 'latex', 'wordpress'); |
| 68 |
foreach ($my_tags as $my_tag) { |
| 69 |
if (stripos($post['post_content'], $my_tag) !== false) |
| 70 |
array_push($post['tags_input'], $my_tag); |
| 71 |
} |
| 72 |
return $post; |
| 73 |
} |
| 74 |
|
| 75 |
function add_custom_field($post) { |
| 76 |
add_post_meta($post['ID'], 'postie', 'postie'); |
| 77 |
return $post; |
| 78 |
} |
| 79 |
|
| 80 |
//changes the email to the admin email if the sender was from the example.com domain |
| 81 |
function change_email($email) { |
| 82 |
if (stristr($email, '@example.com')) |
| 83 |
return get_option("admin_email"); |
| 84 |
return $email; |
| 85 |
} |
| 86 |
|
| 87 |
|