开发者

TinyMCE editors in meta boxes, not saving P tag

for all the hell that the autop function seems to give me when I don't want it, I have several custom meta boxes with tinyMCE textareas. and now they aren't saving

tags.. they seem to be ok w/ saving other html markup.

my html for开发者_如何学Go one of my boxes looks like:

<div class="customEditor">
    <div class="custom_upload_buttons" class="hide-if-no-js"><?php do_action( 'media_buttons' ); ?></div>
    <?php $mb->the_field('below_content'); ?>
    <textarea rows="10" cols="50" name="<?php $mb->the_name(); ?>" rows="3"><?php $mb->the_value(); ?></textarea>
</div>

the naming and stuff is all handled by WPAlchemy, hence the weird $mb->the_name() stuff

function my_admin_print_footer_scripts() { ?>

/*

/* * Multiple TinyMCE Settings */

settings = { mode:"specific_textareas", width:"100%", theme:"advanced", skin:"wp_theme", theme_advanced_buttons1:"bold,italic,strikethrough,underline,|,bullist,numlist,blockquote,|,justifyleft,justifycenter,justifyright,|,link,unlink,|,spellchecker", theme_advanced_buttons2:"formatselect,XXXforecolor,|,pastetext,pasteword,removeformat,|,outdent,indent,|,undo,redo,|,code", theme_advanced_buttons3:"", theme_advanced_buttons4:"", language:"en", spellchecker_languages:"+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv", theme_advanced_toolbar_location:"top", theme_advanced_toolbar_align:"left", theme_advanced_statusbar_location:"bottom", theme_advanced_resizing:"1", theme_advanced_resize_horizontal:"", dialog_type:"modal", relative_urls:"", remove_script_host:"", convert_urls:"", apply_source_formatting:"", remove_linebreaks:"1", gecko_spellcheck:"1", entities:"38,amp,60,lt,62,gt", accessibility_focus:"1", tabfocus_elements:"major-publishing-actions", media_strict:"", paste_remove_styles:"1", paste_remove_spans:"1", paste_strip_class_attributes:"all", wpeditimage_disable_captions:"", plugins:"safari,inlinepopups,spellchecker,paste,wordpress,tabfocus" };

  jQuery(document).ready(function($) {


          var $ta, id, mceID;


          $('.customEditor textarea').each(function(i){
              $ta = $(this);
              id = $ta.attr('id');

              if (!id){
                  id = 'customEditor-' + i;
                  $ta.attr('id',id);
              }
              tinyMCE.settings = settings;
              tinyMCE.execCommand('mceAddControl',

false, id); });

          $('.custom_upload_buttons a').each(function() {
              $(this).click(function() {
                  mceID = $(this).parent().next('textarea').attr('id');
                  window.send_to_editor = window.send_to_editor_clone;
              });

              window.send_to_editor_clone = function(html){
                  tinyMCE.execInstanceCommand(mceID, 'mceInsertContent', false, html);
                  tb_remove();
              }
          });




      });     /* ]]> */</script><?php }

// important: note the priority of 99, the js needs to be placed after tinymce loads add_action('admin_print_footer_scripts','my_admin_print_footer_scripts',99);


Ok, then i guess i know why your editor content does not get saved. You need to call tinyMCE.triggerSave(); this will write the editor content into the html elements they got created for. The tinymce editor consists of an iframe and only moves content between the html element and the iframe.


from: https://wordpress.stackexchange.com/questions/15394/extra-tinymce-editor-strips-p-and-br-tags/17951#17951

Use the save_post hook to manually run wpautop() on the TinyMCE'd fields.


i did sort this out eventually. it turns out that WP does NOT save p tags into the editor. but linebreaks and the like are converted into p tags w/ certain WP filters. so the solution was a combination of altering my textbox to look like:

<textarea class="wysiwyg" rows="10" cols="50" name="<?php $mb->the_name(); ?>" rows="3"><?php echo wp_richedit_pre($mb->get_the_value()); ?></textarea>

and running wpautop (and a few other of the_content's default filters on the output

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜