This is an answer/solution rather than a question, still there maybe some bugs, even I tried on my dev env.
I recently try to use wp_editor in widget/menu, after some search, I did not find a complete solution as I want.
I would share my solution in below after I dig into wp's code by hours:
Working solution:
p.s. you'd have asked at WP.SE: https://wordpress.stackexchange.com/a/192132/33667
add action in wordpress, lets say
My_Action_Name
(also note, textarea IDMy_TextAreaID_22
):now, in Dashboard, execute this function (note, using of
My_TextAreaID_22
andMy_Action_Name
):I have faced similar issue. I solved the issue by using following
1. Added following filter to open the editor always in visual mode in main page
2. In Ajax content used following for editor
3. In Ajax content added following JS code
There maybe hacking involved, however, I tried to minimize them.
To make wp_editor can work in dynamic html (which means without reload page, js changes the page structure), there are two major issues need to take care:
For [tinymce]:
a. need reset UI properly
solution is [remove mce instance] -> [get proper mce settings] -> [re-init a new mce instance]
in js code (id means textarea id):
b. need data write back to textarea before submit
in js code:
For [Quick Tags]:
a. Re-init tags
b. Switch to proper tab (mce tab or quick tag tab)
[switch to current tab mode]
both above in js code:
Also, please remember if you use ajax, every time post back mce UI, you need re-do [reset mce UI] and [Qtags] in you js. A easy solution is using js code in you post back html, and detect in php of:
$isAjax = defined( 'DOING_AJAX' ) && DOING_AJAX == true );
About default settings in js value:
mce :
tinyMCEPreInit.mceInit
qtags :
tinyMCEPreInit.qtInit
If you try to use default setting for widget mode, you need locate default settings.
To get widget template id, in js code:
So you can get settings by:
for mce:
For Qtags:
For the complete code sample, please check : https://github.com/hezachary/wordpress-wysiwyg-widget/blob/master/widget_wp_editor.class.php
If anyone want use wp_editor in menu walk for admin, the principle should be the same.
If you have any question or better solut please comment, thanks.