如何获取事件的wordpress's oEmbed对象加载在TinyMCE

How to get event of wordpress's oEmbed object is loaded in TinyMCE

本文关键字:oEmbed 对象 TinyMCE 加载 wordpress 何获取 获取 事件      更新时间:2023-09-26

我将链接粘贴到WordPress TinyMCE编辑器中,像这样:https://gist.github.com/kolesnikof/642ae1317cc23b87977f/

然后得到oEmbed对象:http://prntscr.com/7wlsrz

通过在functions.php中添加这样的代码:

<?php
    /**
     * Usage:
     * Paste a gist link into a blog post or page and it will be embedded eg:
     * https://gist.github.com/2926827
     *
     * If a gist has multiple files you can select one using a url in the following format:
     * https://gist.github.com/2926827?file=embed-gist.php
     */
    wp_embed_register_handler( 'gist', '/https:'/'/gist'.github'.com'/('d+)('?file=.*)?/i', 'wp_embed_handler_gist' );
    function wp_embed_handler_gist( $matches, $attr, $url, $rawattr ) {
        $embed = sprintf(
            '&lt;script src="https://gist.github.com/%1$s.js%2$s"&gt;&lt;/script&gt;',
            esc_attr($matches[1]),
            esc_attr($matches[2])
        );
        return apply_filters( 'embed_gist', $embed, $matches, $attr, $url, $rawattr );
    }
?>

我的问题:我想突出oEmbed代码,但我不知道事件处理程序触发ajax完成加载oEmbed内容

我解决了问题,但决策并不优雅:

添加脚本到oEmbed对象

if ( is_admin() ) $embed .= '<script>window.top.Prism.highlightElement(document.getElementsByTagName(''pre'')[0]);</script>';