I’m trying to add a content_save_pre filter to update a custom field based on text in the content, e.g. [something]Thing[/something] will tell the plugin to set a custom field to “Thing”.
My code (below) works fine when posting through the web interface, but fails on the clients I’ve tried (MarsEdit and WordPress iOS) and also the “Press This” bookmarklet. The [] tags get removed, but the custom field doesn’t get set.
function dfll_get_link($post_content) {
$dflink = dfll_find_link($post_content);
if ($dflink) {
global $post;
$post_id = $post->ID;
update_post_meta($post_id, 'linked_list_url', $dflink);
}
$temp = '/(' . dfll_regesc('[ll]') . '(.*?)' . dfll_regesc('[/ll]') . ')/i';
$post_content = (preg_replace($temp, '', $post_content));
return $post_content;
}
add_filter('content_save_pre', 'dfll_get_link');
From some testing, it seems that the $post_id variable isn’t being set. Is there a way to get the post ID in these cases? Or should I try and add the filter to a different hook? (I can’t think of any that fit, though.)
Found the solution, using Justin Blanton’s CF Setter plugin. Extract the information and store as a global, then apply the setting as an action for save_post.