Support

Account

Forum Replies Created

  • We figured out that the oemebed functions aren’t cached so we wrote a simple snippet to enable transient cache for oembeds. Possibily not the best solution out there but it works on all our WordPress installations (100+):

    if( !defined('PIX_OEMBED_CACHE_KEY') ) {
                define('PIX_OEMBED_CACHE_KEY', 'pix_oembed_');
            }
    
            function _wp_custom_oembed_cache_key($url, $args) {
                $args_serialized = serialize($args);
                return PIX_OEMBED_CACHE_KEY . md5("{$url}-{$args_serialized}");
            }
    
            /**
            * This function caches the result
            */
            function pix_cache_wp_oembed_get_function($data, $url, $args) {
    
                set_transient( _wp_custom_oembed_cache_key($url, $args), $data, 14*DAY_IN_SECONDS);
                return $data;
    
            }
            add_filter('oembed_result', 'pix_cache_wp_oembed_get_function', 999, 3);
    
            /**
            * This function serves the cached result
            */
    
            function pix_serve_wp_oembed_get_function($result, $url, $args) {
    
                if(trim($url) === '') {
                    return '';
                }
    
                if($cached_result = get_transient(_wp_custom_oembed_cache_key($url, $args))) {
                    return $cached_result;
                }
    
                return $result;
    
            }
            add_filter('pre_oembed_result', 'pix_serve_wp_oembed_get_function', 2, 3);

    Feel free to let me know if it works for you!

  • In the meantime I made some researches and found out that the ACF Oembed Field does not seem to cache any of the oembed requests. I already filed a support ticket. 🙂

  • We have exactly the same problem and that’s because WordPress creates the player via the admin-ajax.php, resulting in that the request to the youtube oembed API comes from your server and not from your computer.

    We host our WordPress Sites ourselves and we have 100+ sites running on our server. Some sites are heavily using ACF oEmbed.

    Because WordPress handles the oembed request itself youtube gets a lot of requests from our server IP and we are hitting the quota limit.

    This is the result of the curl:
    curl https://www.youtube.com/watch?v=egSvdEJZRBk

    <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
    <TITLE>302 Moved</TITLE></HEAD><BODY>
    <H1>302 Moved</H1>
    The document has moved
    <A HREF="https://www.google.com/sorry/index?continue=https://www.youtube.com/watch%3Fv%3DegSvdEJZRBk&q=EhAqAQSIAGYQALAcDF4AAAABGPyv5fQFIhkA8aeDS54ikJN6T6hIAXwP4RDLMyzfx9vjMgFy">here</A>.
    </BODY></HTML>

    My take would be that ACF could enable an option to store the complete oembed response from google in the postmeta instead of only saving the entered url. With this, the frontend does not have to request the youtube oembed api everytime a uncached version of the site is loaded.

    Is this realistic?

Viewing 3 posts - 1 through 3 (of 3 total)