ユーザーがいくつかのオプションを選択できるようにするダイアログボックスを表示するボタンをWordPress Visual Editorに追加しようとしています。次に、ボタンをクリックして、それらのオプションに基づいてコンテンツを挿入します。
これを関数に入れることで、ダイアログボックスを表示することができました:
<?php
function fp_plugin_function_callback() { ?>
<p><select name="my_dialog_options">
<option value="1">First option</option>
<option value="2">Second option</option>
<option value="3">Third option</option>
</select></p>
<p><input type="submit" class="button-primary" value="Go" /></p>
<?php }
add_action('wp_ajax_fp_plugin_function', 'fp_plugin_function_callback');
?>
そして、このJavaScriptで:
(function() {
tinymce.create('tinymce.plugins.fp_split_content', {
init : function(ed, url) {
ed.addButton('fp_split_content', {
title : 'Insert Split Content',
image : url+'/images/split.png',
onclick : function() {
ed.windowManager.open({
file: ajaxurl + '?action=fp_plugin_function',
width : 400 + parseInt(ed.getLang('highlight.delta_width', 0)),
height : 400 + parseInt(ed.getLang('highlight.delta_height', 0))
});
var content = ed.selection.getContent({format : 'html'});
ed.execCommand('mceInsertContent', false, content);
}
});
},
createControl : function(n, cm) {
return null;
}
});
tinymce.PluginManager.add('fp_split_content', tinymce.plugins.fp_split_content);
})();
答えが見つからないのは、ユーザーが選択したオプションをビジュアル エディターに取り込む方法です。