Recientemente conseguí esto funcionando. Debes buscar y reemplazar metaname
con el nombre de tu meta box.
La clave para mantener el formateo era usar wpautop();
al guardar los datos.
add_action( 'add_meta_boxes', 'add_metaname_box');
add_action( 'save_post', 'metaname_save');
function add_metaname_box() {
add_meta_box(
'metaname_id',
__( 'metaname text', 'metaname_textdomain'),
'metaname_custom_box',
'page'
);
}
function metaname_custom_box() {
global $post;
wp_nonce_field( plugin_basename( __FILE__ ), 'metaname_noncename' );
$data = get_post_meta($post->ID, 'metaname_custom_box', true);
echo <<<EOT
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#metaname_custom_box").addClass("mceEditor");
if ( typeof( tinyMCE ) == "object" &&
typeof( tinyMCE.execCommand ) == "function" ) {
tinyMCE.execCommand("mceAddControl", false, "metaname_custom_box");
}
});
</script>
<textarea id="metaname_custom_box" name="metaname_custom_box">$data</textarea>
EOT;
}
function metaname_save($post_id) {
global $post;
// Verify
if ( !wp_verify_nonce( $_POST['metaname_noncename'], plugin_basename(__FILE__) )) {
return $post_id;
}
if ( 'page' == $_POST['post_type'] ) {
if ( !current_user_can( 'edit_page', $post_id ))
return $post_id;
} else {
if ( !current_user_can( 'edit_post', $post_id ))
return $post_id;
}
$key = 'metaname_custom_box';
$data = wpautop($_POST[$key]);
// New, Update, and Delete
if(get_post_meta($post_id, $key) == "")
add_post_meta($post_id, $key, $data, true);
elseif($data != get_post_meta($post_id, $key, true))
update_post_meta($post_id, $key, $data);
elseif($data == "")
delete_post_meta($post_id, $key, get_post_meta($post_id, $key, true));
}
'remove_linebreaks' => true
a'remove_linebreaks' => false
. Pero no funciona si especifico'remove_linebreaks' => false
en la matriz de configuración pasada a la función