2014-01-11 77 views
0

我嘗試爲wordpress製作一個插件,在TinyMCE編輯器中需要一個按鈕。我嘗試了幾個教程,並且可以在工具欄中獲取按鈕,但不會打開一個窗口。我試圖以此爲榜樣:http://return-true.com/2011/12/adding-tinymce-button-to-wordpress-via-a-plugin/WordPress TinyMCE按鈕,不會打開窗口

我的javascript代碼:

// 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); 
})(); 

而且我實現在WordPress的PHP代碼:

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; 
} 

有人能明白爲什麼我不能打開窗口,當點擊按鈕?

回答

0

我做到了!它現在有效。

問題是汽車應該是「自動」。但我不能讓汽車工作,所以現在我只有一個固定的高度。

height : "auto", 
0

不知道這是否適用,但由於PHP短打開標記<?與在tinymce jQuery庫中使用這些字符之間的衝突,我看到了問題。

端向上改裝WP-包括/ JS/TinyMCE的/ tiny_mce.js(或可能WP-包括/ JS/TinyMCE的/可溼性粉劑tinymce.js)

改變事件

{c.push("<?", 

{c.push("<" + "?", 

感謝MarcBB的修復。

+0

我不確定我明白你的意思。我不會通過更改wp文件來修復它。因爲那麼每個使用插件的人都必須這樣做?和其他插件與按鈕工作正常。 – mschadegg

+0

這是在黑暗中拍攝的 - tinymce在更新後停止了適當渲染,結果發現它是服務器PHP設置中啓用的短標籤導致了我們的問題。在我們的案例中,選擇是在禁用短期標籤,或改變tinymce。 – MarkV