Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to create a plugin which updates the post's content in the Admin panel. For example, on the Edit post page, the user sees his draft content. If he clicks on a button from a meta box plugin, I want new HTML to be appended to the post content. Ideally without refreshing the page. Zemanta does this and I am trying to figure out the right method for achieving that effect.

NOTE: I am brand new to coding with Wordpress, so please let me know if/how my question needs to be clarified further.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

This type of thing is most easily done from the TinyMCE editor through a plugin. Details of creating one using WordPress filters can be found here:

http://codex.wordpress.org/TinyMCE_Custom_Buttons

function myplugin_addbuttons() {
   // Don't bother doing this stuff if the current user lacks permissions
   if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )
     return;

   // Add only in Rich Editor mode
   if ( get_user_option('rich_editing') == 'true') {
     add_filter("mce_external_plugins", "add_myplugin_tinymce_plugin");
     add_filter('mce_buttons', 'register_myplugin_button');
   }
}

function register_myplugin_button($buttons) {
   array_push($buttons, "separator", "myplugin");
   return $buttons;
}

// Load the TinyMCE plugin : editor_plugin.js (wp2.5)
function add_myplugin_tinymce_plugin($plugin_array) {
   $plugin_array['myplugin'] = URLPATH.'tinymce/editor_plugin.js';
   return $plugin_array;
}

// init process for button control
add_action('init', 'myplugin_addbuttons');

The documentation on how to write the required editor_plugin.js file to perform your desired insert will be found on the TinyMCE site:

http://www.tinymce.com/wiki.php/TinyMCE3x:Creating_a_plugin

http://www.tinymce.com/wiki.php/API3:tinymce.api.3.x

http://www.tinymce.com/wiki.php/TinyMCE3x:TinyMCE_3.x

If you really must perform the insert by clicking a button in a meta box, then perhaps a close examination of the Zemanta plugin code will be helpful. Comment on this answer with a link to that plugin if you'd like some help with that.

share|improve this answer
    
Thanks marfarma. I went to the API and found the following function to give me all that I needed to keep making progress: tinyMCE.activeEditor.selection.getContent(); –  Shaan Sep 26 '11 at 21:13
    
Please 'accept' the answer if your question was answered. It helps people, who find it later through search, to know that an answer was found. –  marfarma Sep 26 '11 at 21:28
    
FYI: all links goes to 404 –  Sisir Aug 29 '13 at 9:57
    
Fixed the tinymce links - apparently the site was restructured without page level re-directs. –  marfarma Aug 29 '13 at 14:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.