duanlanqian9974 2014-01-11 15:49
浏览 64
已采纳

WordPress TinyMCE按钮,不会打开窗口

I try to make a plugin for wordpress, where I need a button in the TinyMCE editor. I have tried several tutorials, and I can get the button in the toolbar, but it will not open a window. I have tried to follow this example: http://return-true.com/2011/12/adding-tinymce-button-to-wordpress-via-a-plugin/

My javascript code:

// JavaScript Document
(function() {
    tinymce.create("tinymce.plugins.afflpad", {
        init : function(ed, url) {
            ed.addCommand("afflpad_click", function() {
                ed.windowManager.open({
                    file : url.substring(0, url.length -2) + "afflpad_selector.php",
                    width : 480,
                    height : auto,
                    inline: 1,
                }, {
                    plugin_url : url    
                });
            });
            ed.addButton("afflpad_button", {
                title : "Affiliate Link",
                cmd : "afflpad_click",
                image : url.substring(0, url.length -2) + 'img/afflpad_button.png'
            });
        },
        getInfo : function() {
            return {
                longname : "Affiliate links",
                author : "NAME",
                authorurl : "HOMEPAGE",
                infourl : "HOMEPAGE",
                version : tinymce.majorVersion + "." + tinymce.minorVersion
            };
        }
    });
    tinymce.PluginManager.add("afflpad", tinymce.plugins.afflpad);
})();

And my PHP code for implementing in wordpress:

function afflpad_mce_buttonhooks() {
    if(current_user_can("edit_posts") && current_user_can("edit_pages") && get_user_option("rich_editing") == "true") {
        add_filter("mce_external_plugins", "afflpad_register_tinymce_javascript");
        add_filter("mce_buttons", "afflpad_register_mce_buttons");  
    }
}

add_action("init", "afflpad_mce_buttonhooks");

function afflpad_register_tinymce_javascript($plugin_array) {
    $plugin_array["afflpad"] = plugins_url("/js/afflpad_tinymce_plugin.js", __file__);
    return $plugin_array;
}

function afflpad_register_mce_buttons($buttons) {
    array_push($buttons, "|", "afflpad_button");
    return $buttons;
}

Can someone see why I can't open a window, when clicking on the button?

  • 写回答

2条回答 默认 最新

  • dsfliu1129 2014-01-11 20:55
    关注

    I did it! It works now.

    The problem is that auto should be "auto". But I can't get auto to work as well, so now I have just a fixed height.

    height : "auto",
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条