• Resolved merxhanemini

    (@merxhanemini)


    Hi,

    I tried what is suggested in this closed topic https://wordpress.org/support/topic/advanced-custom-fields-compatibility?replies=7 but it seems to me that it doesn’t save the youtube image as featured image. But when I change the link on my custom field it saves the featured image of the previous link that was published before(the one which it didn’t retrieve). Why does this happen?

    My field type is ACF oembed returning HTML(see the link for the image): http://imgur.com/a/wrxf1

    Here is my code:

    /**
     * Fetching the image from the video link custom field
     * @param  string $content the filtered content from the custom field
     * @return string  return formated string from the video url that fetches the image.
     * First checks for the maxresdefault image size from YouTube,vimeo etc, and if that doesn't exist, it moves to hqdefault
     */
    function nen_fetch_video_image_from_plugin( $content ) {
        $nem_media_field = get_field( 'nem_video_link' );
        if ( ! empty( $nem_media_field ) ) {
            return $nem_media_field;
        }
    
        return $content;
    }
    add_filter( 'wds_featured_images_from_video_filter_content', 'nen_fetch_video_image_from_plugin' );

    https://wordpress.org/plugins/automatic-featured-images-from-videos/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support Michael Beckwith

    (@tw2113)

    The BenchPresser

    My guess is that the returned get_field value is one that is already rendering the iframe/oembed and because of that, it’s not matching the regex in our plugin. The regex is expecting the regular youtube url, something like https://www.youtube.com/watch?v=XDhnl8_o_nk or similar.

    Thread Starter merxhanemini

    (@merxhanemini)

    Thank you for you quick reply.
    I changed my function to retrieving the regular youtube url:

    /**
     * Fetching the image from the video link custom field
     * @param  string $content the filtered content from the custom field
     * @return string  return formated string from the video url that fetches the image.
     * First checks for the maxresdefault image size from YouTube,vimeo etc, and if that doesn't exist, it moves to hqdefault
     */
    function nen_fetch_video_image_from_plugin( $content ) {
        //get the regular youtube url: https://youtube.com?watcht=somecode
        $nem_media_field = get_field('nem_video_link', false, false);
        if ( ! empty( $nem_media_field ) ) {
            return $nem_media_field;
        }
    
        return $content;
    }
    add_filter( 'wds_featured_images_from_video_filter_content', 'nen_fetch_video_image_from_plugin' );

    But it seems still doesn’t fetch. And when I want to edit the post and change the video from the custom field it doesen’t change the thumbnail it stays from the previous one. Somehow it is not triggering save_post or i dont know.

    Plugin Support Michael Beckwith

    (@tw2113)

    The BenchPresser

    Can you paste an example of what’s coming through in $nem_media_field ? If this is just the raw url for a youtube video like “https://www.youtube.com/watch?v=XDhnl8_o_nk” then it should catch. If it’s the processed oembed iframe and whatnot, then it may not.

    Regarding the image itself, the code checks to see if there’s an image already set, and if so, it will return early, not replacing. This is by design. If you are going to be updating the video url/embed regularly, you may want to wire up some custom functionality that will remove the featured image when the video gets changed, so that Auto Featured Images can process the rest.

    Thread Starter merxhanemini

    (@merxhanemini)

    It gets the raw youtube url. But I thin the problem is that when it checks for remote headers the maxresdefault.jpg is neve 404 there is a small photo which is to small to be saved as featured image.

    if ( $youtube_id ) {
    		// Check to see if our max-res image exists.
    		$remote_headers = wp_remote_head( 'http://img.youtube.com/vi/' . $youtube_id . '/maxresdefault.jpg' );
    		$is_404 = ( 404 === wp_remote_retrieve_response_code( $remote_headers ) );
    
    		$video_thumbnail_url = ( ! $is_404 ) ? 'http://img.youtube.com/vi/' . $youtube_id . '/maxresdefault.jpg' : 'http://img.youtube.com/vi/' . $youtube_id . '/hqdefault.jpg';
    	} elseif ( $vimeo_id ) {
    		$vimeo_data = wp_remote_get( 'http://www.vimeo.com/api/v2/video/' . intval( $vimeo_id ) . '.php' );
    		if ( isset( $vimeo_data['response']['code'] ) && '200' == $vimeo_data['response']['code'] ){
    			$response = unserialize( $vimeo_data['body'] );
    			$video_thumbnail_url = isset( $response[0]['thumbnail_large'] ) ? $response[0]['thumbnail_large'] : false;
    		}
    	}
    Thread Starter merxhanemini

    (@merxhanemini)

    For Example this video http://img.youtube.com/vi/xcSltFDbcGY/maxresdefault.jpg has a maxresdefault.jpg but that is a small tiny img so actually maxresdefault is never 404. And as you know small images can not be set as featured image

    Thread Starter merxhanemini

    (@merxhanemini)

    One more thing Save Draft dosen’t work on first it should be clicked twice.

    I don’t know why.

    Sorry I am keeping posting one by one. I really need this feature.

    Thank you for your help .

    Plugin Support Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hrm…

    Can you try this version of the plugin out? https://github.com/WebDevStudios/Automatic-Featured-Images-from-Videos/archive/master.zip

    https://github.com/WebDevStudios/Automatic-Featured-Images-from-Videos

    I was holding off on releasing it as at the time of the commits I had already released a bugfix update, but if this fixes it for you, then I’ll probably push it out now.

    Thread Starter merxhanemini

    (@merxhanemini)

    I have this 1.0.4 I already updated it. Still gives me an error on save draft. I have to click twice. I filtered to never look for maxresdefault only hqdefault but save draft twice is giving me headache.

    Plugin Support Michael Beckwith

    (@tw2113)

    The BenchPresser

    Is this one of your own videos, or is it from someone else whose account you don’t have access to.

    Part of me is curious if you can get the api images regenerated and updated.

    Otherwise, I admit I’m not sure what to say, as I don’t have ACF available for testing of any sort, and we can only work with what Youtube returns from its API.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘ACF Advanced Custom fields oEmbed Field type’ is closed to new replies.