/**
 * update images article meta when post saved
 * 
 * @access public
 * @param mixed $meta_id
 * @param mixed $post_id
 * @param mixed $meta_key
 * @param mixed $meta_value
 * @return void
 */
function ms_updated_featured_image_postmeta($post_id)
{
    // If this is just a revision, don't do anything.
    if (wp_is_post_revision($post_id)) {
        return;
    }
    // need to be articles post type
    if ('articles' !== $_POST['post_type']) {
        return;
    }
    // If this is an autosave, our form has not been submitted, so we don't want to do anything.
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    $thumbnail_id = get_post_meta($post_id, '_thumbnail_id', true);
    $prev_thumbnail_id = get_post_meta($post_id, 'articleImg', true);
    // if we have a featured image
    if ($thumbnail_id) {
        $image = wp_get_attachment_image_src($thumbnail_id, 'full');
        // if the image has changed
        if ($image && $thumbnail_id !== $prev_thumbnail_id) {
            $image_src = $image[0];
            $attach_id = ms_save_resized_image_to_uploads($image_src);
            // resize
            $image_hero = ms_get_image_url($attach_id, MS_IMAGE_SIZE_HERO);
            $image_med = ms_get_image_url($attach_id, MS_IMAGE_SIZE_MEDIUM);
            $image_small = ms_get_image_url($attach_id, MS_IMAGE_SIZE_SMALL);
            // save image
            update_post_meta($post_id, 'articleImg', $thumbnail_id);
            update_post_meta($post_id, 'imageHero', $image_hero);
            update_post_meta($post_id, 'imageMedium', $image_med);
            update_post_meta($post_id, 'imageSmall', $image_small);
        }
    } else {
        // no featured image, so empty image fields
        update_post_meta($post_id, 'articleImg', '');
        update_post_meta($post_id, 'imageHero', '');
        update_post_meta($post_id, 'imageMedium', '');
        update_post_meta($post_id, 'imageSmall', '');
    }
}
/**
 * testing image upload.
 * 
 * @access public
 * @return void
 */
function ms_run_images_test()
{
    $image_url = 'http://editorial.mansionglobal.com/wp-content/uploads/2015/05/BN-HZ507_0424FO_GR_20150420184130.jpg';
    echo $image_url;
    $attach_id = ms_save_resized_image_to_uploads($image_url);
    // get the URL - this should have been moved to S3 if using the Amazon S3 plugin
    $attach_src = ms_get_image_url($attach_id, MS_IMAGE_SIZE_HERO);
    echo "<pre>";
    print_r($attach_src);
    echo "</pre>";
    $attach_src = ms_get_image_url($attach_id, MS_IMAGE_SIZE_MEDIUM);
    echo "<pre>";
    print_r($attach_src);
    echo "</pre>";
    $attach_src = ms_get_image_url($attach_id, MS_IMAGE_SIZE_SMALL);
    echo "<pre>";
    print_r($attach_src);
    echo "</pre>";
    die;
}