laboratorio caffeina

in few words, just developing

 

Add TinyMCE to author description in Wordpress

Ok, second chance to me, after the Restrict authors access to edit comments plugin I did the second one.

I think that the name is quite explicative: I wanted to add the wysiwyg to the user description .

PHP:
  1. <?php
  2. /*
  3. Plugin Name: Add TinyMce to Author Profile
  4. Plugin URI: http://www.laboratoriocaffeina.it/development/2007/08/22/add-tinymce-to-author-description-in-wordpress.html
  5. Description: Adds WYSIWYG to Author profile
  6. Version: 0.1
  7. Author: cedmax
  8. Author URI: http://www.dioblog.it
  9. */
  10.  
  11. if ((strpos($_SERVER['SCRIPT_NAME'], 'wp-admin/user-edit.php')) or (strpos($_SERVER['SCRIPT_NAME'], 'wp-admin/profile.php'))) {
  12.     add_action('admin_head', 'add_tinymce');
  13. }
  14.  
  15. remove_filter('pre_user_description', 'wp_filter_kses');
  16. add_filter('pre_user_description', 'wpautop');
  17.  
  18. function add_tinymce() {?>
  19.  
  20.     <script type="text/javascript" src="<?php echo get_settings('home'); ?>/wp-includes/js/tinymce/tiny_mce_gzip.php?ver=20070326"></script>
  21.     <script type="text/javascript">
  22.     //<![CDATA[
  23.  
  24.     function brstonewline(element_id, html, body) {
  25.         html = html.replace(/<br\s*\/>/gi, '\n');;
  26.         return html;
  27.     }
  28.  
  29.     function insertHTML(html) {
  30.         tinyMCE.execCommand('mceInsertContent',false, html);
  31.     }
  32.  
  33.     tinyMCE.init({
  34.         mode : "exact",
  35.         elements : "description",
  36.         theme : "advanced",
  37.         theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,undo,redo,link,unlink",
  38.         force_p_newlines : false,
  39.             force_br_newlines : true,
  40.         gecko_spellcheck : true,
  41.         theme_advanced_buttons2 : "",
  42.         theme_advanced_buttons3 : "",
  43.         theme_advanced_toolbar_location : "top",
  44.         theme_advanced_toolbar_align : "left",
  45.             save_callback : "brstonewline",
  46.             height : "300",
  47.         extended_valid_elements : "a[name|href|title],font[face|size|color|style],span[class|align|style]"
  48.     });
  49.     //]]>
  50.     </script>
  51.  
  52. <?php } ?>

INSTRUCTION:
download v.0.1 and copy the file into wp-content/plugins.
activate it.
Now you should see in the edit user details the wysiwyg editor.
You can manage to modify TinyMCE script, following instruction

Hope you like it
tested on wordpress 2.2

IN ORDER TO LET IT WORK IN 2.5
replace this part of code:

PHP:
  1. function add_tinymce() {?>
  2.  
  3.     <script type="text/javascript" src="<?php echo get_settings('home'); ?>/wp-includes/js/tinymce/tiny_mce_gzip.php?ver=20070326"></script>
  4.     <script type="text/javascript">
  5.     //<![CDATA[
  6.  
  7.     function brstonewline(element_id, html, body) {
  8.         html = html.replace(/<br\s*\/>/gi, '\n');;
  9.         return html;
  10.     }
  11.  
  12.     function insertHTML(html) {
  13.         tinyMCE.execCommand('mceInsertContent',false, html);
  14.     }
  15.  
  16.     tinyMCE.init({
  17.         mode : "exact",
  18.         elements : "description",
  19.         theme : "advanced",
  20.         theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,undo,redo,link,unlink",
  21.         force_p_newlines : false,
  22.             force_br_newlines : true,
  23.         gecko_spellcheck : true,
  24.         theme_advanced_buttons2 : "",
  25.         theme_advanced_buttons3 : "",
  26.         theme_advanced_toolbar_location : "top",
  27.         theme_advanced_toolbar_align : "left",
  28.             save_callback : "brstonewline",
  29.             height : "300",
  30.         extended_valid_elements : "a[name|href|title],font[face|size|color|style],span[class|align|style]"
  31.     });
  32.     //]]>
  33.     </script>
  34. <?php } ?>

with this:

PHP:
  1. function add_tinymce() {?>
  2.  
  3.     <script type="text/javascript" src="<?php echo get_settings('home'); ?>/wp-admin/js/editor.js?ver=20080325"></script>
  4.  
  5. <script type="text/javascript" src="<?php echo get_settings('home'); ?>/wp-includes/js/tinymce/tiny_mce_config.php?ver=20080327"></script>
  6.     <script type="text/javascript">
  7.     //<![CDATA[
  8. window.onload= function() {
  9. tinyMCE.execCommand("mceAddControl", false, "description");
  10. }
  11.  // ]]>
  12.    
  13.     </script>
  14.  
  15. <?php } ?>

 
 
commenti
 
Weblog Tools Collection » Blog Archive » WordPress Plugin Releases for 8/23:

[...] Author TinyMCE enhances the author description field with the TinyMCE Editor. [...]

 
 
 
Skylog » Blog Archive » links for 2007-08-24:

[...] Add TinyMCE to author description in Wordpress (tags: wordpress) [...]

 
 
Author TinyMCE | ????????:

[...] Add TinyMCE to author description in Wordpress | laboratorio caffeina [...]

 
 
Poster’s Notes » ?????????…:

[...] Add TinyMce to Author Profile 0.1 Advanced WYSIWYG Editort 0.2 (?????i???????) Audio player 1.2.3 BackUpWordPress 0.2.6 Disk Usage 2.0 Google Sitemaps 3.0b1 HTML Purified 0.2.4 ImageManager 2.4.1 LiveJournal Crossposter 1.5 (?????i???????) RusToLat 0.2 Search and Replace 1.6 Search Term HighLiter 1.0 Seo-Without-Category 1.0 Shutter Reloaded 1.1 Smilies Themer 0.2 Beta TheRussianDate 1.01 wp-comment-spam-stopper v1.1.1   [...]

 
 
HTML in Autoren-Beschreibung » Peruns Weblog:

[...] der Suche habe ich zwar ein Plugin gefunden, welches sogar verspricht den visuellen Editor innerhalb de Beschreibung einzubinden. Ich [...]

 
 
 
 
Jordan:

Thank you for this plugin its awesome. +1 geek point ^_^

 
 
Jordan:

Is there any chance of this being upgraded to work on wordpress 2.5?

 
 
Robert:

The problem of this plugin with WP2.5 is that the editor TinyMCE is called with this code:

/wp-includes/js/tinymce/tiny_mce_gzip.php?ver=20070326">

The file tiny_mce_gzip.php is not available in WP2.5 anymore respectively has a file size of 0 bytes (I dont know if this is correct or a bug of WP).

A workaround is to call TinyMCE directly, which means you have to change the line above into

/wp-includes/js/tinymce/tiny_mce.js">

and it works again :-)

 
 
cedmax:

sorry for not updating the plugin (I’m a little busy here), but I’ve already got the solution:

change the function add_tinymce with this one:

function add_tinymce() {?>
<script type=”text/javascript” src=”< ?php echo get_settings('home'); ?>/wp-admin/js/editor.js?ver=20080325″></script>
<script type=”text/javascript” src=”< ?php echo get_settings('home'); ?>/wp-includes/js/tinymce/tiny_mce_config.php?ver=20080327″></script>
<script type=”text/javascript”>
//<![CDATA[
window.onload= function() {
tinyMCE.execCommand("mceAddControl", false, "description");
} // ]]></script>
< ?php } ?>

 
 
Robert:

Thanx for the code - be aware that spaces in it are not shown correctly. I also had to change the quotes in order to get it working. If you just copy and paste the code above, it won´t work!

 
 
cedmax:

you’re right: I’d better put it in the post: comments aren’t the right place

 
 
Sarah Lewis:

Thanks for the example! I modified it just slightly to add a WYSIWYG editor to the category description field in the category editor, and it worked very well.

 
 
WordPress Plugin Releases for 8/23:

[...] Author TinyMCE enhances the author description field with the TinyMCE Editor. [...]

 
 
WP Plugs October 19, 2007 « blog.designcreatology:

[...] Author TinyMCE enhances the author description field with the TinyMCE Editor. [...]

 
 
The Blog for DesignCreatology » Blog Archive » WP Plugs October 19, 2007:

[...] Author TinyMCE enhances the author description field with the TinyMCE Editor. [...]

 
 
pablo:

Hi,
any idea to let it works on wordpress 2.6.2 or higher?

many thanks
pablo

 
 
AndrewJ:

For wordpress 2.7, you’ll need to make the code look like this:


if ( (strpos($_SERVER['SCRIPT_NAME'], ‘wp-admin/user-edit.php’)) or (strpos($_SERVER['SCRIPT_NAME'], ‘wp-admin/profile.php’))) {
add_action(’admin_head’, ‘add_tinymce’);
}
remove_filter(’pre_user_description’, ‘wp_filter_kses’);
add_filter(’pre_user_description’, ‘wpautop’);

function add_tinymce() {

if (function_exists(’wp_tiny_mce’)) wp_tiny_mce(); ?>

//

 
 
Alex Leonard:

Hi there, I’ve been trying to get this to work on 2.7 but haven’t been able to use the above suggestion - nothing happens :(

As a result I ended up doing a more basic TinyMCE init of which I’ve posted info here:

http://wordpress.org/support/topic/229882

I can’t work out the simpler way to do it and am in a bit of a rush, so I’ll have to come back to it.

I think this functionality should really be just included in the WP core..

:)

 
 
Robert:

Make sure, you use the right inverted comas - I copied the code and had to change them from ´ to ‘ - then it worked!

 

Commenta



 
Chiudi
E-mail It