block editor - How to register a embed handler as a fallback to a oEmbed handler?

Testing this with the Embed Gutenberg Block. In the backend it actually shows the video so this seems wrong that it beha

Testing this with the Embed Gutenberg Block. In the backend it actually shows the video so this seems wrong that it behaves differently there.

Registering embed handlers causes the to take priority over the (default) WordPress oEmebed handlers even when priority is set to PHP_INT_MAX. I like to trigger them after the oembed handlers in case they fail. How can I do this?

This code is inside a mu-plugin, but I have more complicated code in my main plugin that has the same issue.

<?php
namespace Nextgenthemes\Debug;

disable_oembed_cache();

add_action( 'init', function() {

    wp_embed_register_handler(
        'arve_dailymotion',
        '#https?://(www\.)?(dai\.ly|dailymotion\/video)/(?<id>[a-z0-9]+)#i',
        __NAMESPACE__ . '\dailymotion_embed_handler',
        PHP_INT_MAX
    );
} );


function dailymotion_embed_handler( array $matches, array $attr, $url, array $rawattr ) {
    return print_r( $matches );
}

function disable_oembed_cache() {

    add_action( 'init', function() {
        $GLOBALS['wpdb']->query( "DELETE FROM {$GLOBALS['wpdb']->postmeta} WHERE meta_key LIKE '%_oembed_%'" );
    } );

    add_action( 'template_redirect', function() {
        $GLOBALS['wpdb']->query( "DELETE FROM {$GLOBALS['wpdb']->postmeta} WHERE meta_key LIKE '%_oembed_%'" );
        $GLOBALS['wp_embed']->cache_oembed( get_queried_object_id() );
    } );

    add_filter( 'oembed_ttl', function( $ttl ) {
      return 1;
    } );
}

Sidenote: In my local testing with the Dailymotion oEmbed I get it to work only every 2nd/3rd time or so. Maybe because I deactivate the cache but its not happening for YouTube.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745192688a4615939.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信