I've tried a number of solutions posted here regarding converting custom fields to featured images - of course in reverse; but non seem to work for me.
What I'm trying to do is grab the Featured Image URL once the image is uploaded and set as a featured image; then automatically set the full size image URL as a custom field. This needs to work on both post Update for existing articles that do not currently have the custom field set and for post Publish for new articles.
As mentioned I have tried numerous suggestions based on this but none seem to work. Here is the last bit of code that I attempted without success though - and the frustrating part is that I cannot seem to debug or get any errors out of this:
add_action('publish_page', 'add_custom_field_automatically');
add_action('publish_post', 'add_custom_field_automatically');
function add_custom_field_automatically($post_ID) {
global $wpdb;
$post_thumbnail_id = get_post_thumbnail_id();
$post_thumbnail_url = wp_get_attachment_url($post_thumbnail_id);
add_post_meta($post_ID, 'lead_image', $post_thumbnail_url, false);
}