【问题标题】:How to get event of wordpress's oEmbed object is loaded in TinyMCE如何在 TinyMCE 中加载 wordpress 的 oEmbed 对象的事件
【发布时间】:2015-10-15 15:54:40
【问题描述】:

我将链接粘贴到 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 内容时的事件处理程序触发

【问题讨论】:

    标签: javascript ajax wordpress tinymce embed


    【解决方案1】:

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

    将脚本添加到 oEmbed 对象

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-19
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 2013-06-22
      • 1970-01-01
      相关资源
      最近更新 更多