wp_editor api没有在自定义用户配置文件字段中写入p标签

时间:2012-02-02 23:45:24

标签: wordpress

我正在使用WP的wp_editor api(使用WP版本3.3.1)在wordpress用户个人资料页面中构建自定义传记字段。

当我添加任何内容时,WSYIWYG编辑器不会将段落标记写入数据库。

我可以使用可视化编辑器添加所有其他标记(粗体,斜体等)&我可以手动添加段落标记并将完整的标记文本保存到数据库中。

还有其他人遇到过这个问题吗?代码我用来在下面的functions.php文件中构建自定义字段。

//ADD EXTRA FIELDS TO USER PROFILE
add_action( 'show_user_profile', 'extra_profile_fields' );
add_action( 'edit_user_profile', 'extra_profile_fields' );
function extra_profile_fields( $user ) {

    //CHECK FOR AUTHOR BIO CONTENT  
    $check_for_bio = get_the_author_meta('authorbio', $user->ID);
    $author_bio = '';
    if (!empty($check_for_bio)) { $author_bio = $check_for_bio; } 

    //BUILD THE INPUT
    echo '<table class="form-table">';
        echo '<tr>';
            echo '<th><label for="authorbio">Author Biography</label></th>';
            echo '<td>';
            $settings = array('wpautop' => true, 'media_buttons' => false);
            wp_editor( $author_bio, 'authorbio', $settings);        
            echo '</td>';
        echo '</tr>';
    echo '</table>';    
}

//SAVE EXTRA FIELDS TO USER PROFILE
add_action( 'personal_options_update', 'save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_profile_fields' );
function save_extra_profile_fields( $user_id ) {
    if ( !current_user_can( 'edit_user', $user_id ) )
        return false;

    update_user_meta( $user_id, 'authorbio', $_POST['authorbio'] );
}

2 个答案:

答案 0 :(得分:4)

解决了这个问题。没有添加the_content过滤器。打印输出时。

<?php
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]&gt;', $content);
?>

http://codex.wordpress.org/Function_Reference/the_content

答案 1 :(得分:1)

对于像我这样的PHP假人,这是一种如何创建输出的可行方法:

<?php 
    $bio_czech = get_the_author_meta('bio_czech',$user->ID);
    echo wpautop($bio_czech);
?>