Dplayer FOR WordPress 添加插入按钮

Dplayer FOR WordPress 添加插入按钮

更新

已瞎搞了一波wordpress的dplayer插件,具体可以去这里看看: API

每次都要复制粘贴或者手打短代码 麻烦
想要在编辑器里添加短代码按钮

所以

开始瞎折腾

在博客主题文件夹内找到functions.php
然后添加如下代码

// wordpress后台HTML编辑器添加自定义快捷标签按钮
 add_action('after_wp_tiny_mce', 'bolo_after_wp_tiny_mce');

 function bolo_after_wp_tiny_mce($mce_settings) {
    ?>
    <script type="text/javascript">
    QTags.addButton('dplayerin','插入Dplayer','[dplayer url="'+dplayerurl+'" pic="'+dplayerpic+'" danmu=true /]','');  
    </script>
<?php
}

有文本框的完整代码(野路子程序员233):

// wordpress后台HTML编辑器添加自定义快捷标签按钮
add_action('media_buttons', 'add_my_media_button',15);
function add_my_media_button() {
    wp_enqueue_script( 'custombackend', '/custom.js', array(), '1.0.0', true );
    echo '
    图片地址:<input type="text" oninput="dplayerurls()" value=""  width=50% id="dplayerpic">
    视频地址:<input type="text" oninput="dplayerurls()" value=""  width=50% id="dplayerurl">
    <script>
        var dplayerurl;
        var dplayerpic;
    
        function dplayerurls(){
           dplayerurl = document.getElementById("dplayerurl").value;
           dplayerpic = document.getElementById("dplayerpic").value;
        }
        function dplayerinsert(){
        document.getElementById("content").value = \'[dplayer url="\' + dplayerurl + \'" pic="\' + dplayerpic + \'" danmu=true / ]\';
      }
        function dplayercode(){
        document.getElementById("dplayercode").value = \'[dplayer url="\' + dplayerurl + \'" pic="\' + dplayerpic + \'" danmu=true / ]\';
      }
        function dplayerin(){  
        content = \'[dplayer url="\' + dplayerurl + \'" pic="\' + dplayerpic + \'" danmu=true / ]\';
        document.getElementById("content").text = content; 
      }
</script>
    <a href="javascript:void(0);" onclick="dplayerinsert()" class="button">插入视频</a>
    代码:<input type="text" value=""  width=50% id="dplayercode">
    <!--<a href="javascript:void(0);" onclick="dplayercode()" class="button">生成代码</a>-->';

}


 add_action('after_wp_tiny_mce', 'bolo_after_wp_tiny_mce');
 
 function bolo_after_wp_tiny_mce($mce_settings) {
    ?>
    
    <script type="text/javascript">  
    QTags.addButton('dplayerin','插入Dplayer','[dplayer url="" pic="" danmu=true /]','');  
    </script>
   
    <?php
}

效果如下

效果图

标签: wordpress, DPlayer