Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 自定义所见即所得文本区域-html文本格式_Wordpress - Fatal编程技术网

Wordpress 自定义所见即所得文本区域-html文本格式

Wordpress 自定义所见即所得文本区域-html文本格式,wordpress,Wordpress,我创建了一个自定义字段。保存到db是可以的。但是当我保存一个页面时,文本不是以格式化的形式保存的,而是用html标记保存的 function sidebar_get_meta( $value ) { global $post; $field = get_post_meta( $post->ID, $value, true ); if ( ! empty( $field ) ) { return is_array( $field ) ? stripsl

我创建了一个自定义字段。保存到db是可以的。但是当我保存一个页面时,文本不是以格式化的形式保存的,而是用html标记保存的

function sidebar_get_meta( $value ) {
    global $post;
    $field = get_post_meta( $post->ID, $value, true );
    if ( ! empty( $field ) ) {
        return is_array( $field ) ? stripslashes_deep( $field ) : stripslashes( wp_kses_decode_entities( $field ) );
    } else {
        return false;
    }
}


function sidebar_add_meta_box() {
    add_meta_box(
        'sidebar-sidebar',
        __( 'sidebar', 'sidebar' ),
        'sidebar_html',
        'page',
        'advanced',
        'default'
    );
}
add_action( 'add_meta_boxes', 'sidebar_add_meta_box' );


function sidebar_html( $post) {
    wp_nonce_field( '_sidebar_nonce', 'sidebar_nonce' ); ?>
    <p>bočný stlpec ak by bolo treba</p>

    <?php
    $content = sidebar_get_meta( 'sidebar_sidebar' );
    $editor_id = 'sidebar_sidebar';

    $settings = array( 
        'media_buttons' => true,
        'quicktags' => true,
        'tinymce' => true,
        'textarea_rows' => 5
    );
    wp_editor( $content, $editor_id, $settings );
}


function sidebar_save( $post_id ) {
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
    if ( ! isset( $_POST['sidebar_nonce'] ) || ! wp_verify_nonce( $_POST['sidebar_nonce'], '_sidebar_nonce' ) ) return;
    if ( ! current_user_can( 'edit_post', $post_id ) ) return;

    if ( isset( $_POST['sidebar_sidebar'] ) )
        update_post_meta( $post_id, 'sidebar_sidebar', esc_attr( $_POST['sidebar_sidebar'] ) );
}
add_action( 'save_post', 'sidebar_save' );
函数侧栏\u get\u meta($value){
全球$员额;
$field=get\u post\u meta($post->ID,$value,true);
如果(!空($field)){
返回是数组($field)?stripslashes_deep($field):stripslashes(wp_kses_decode_entities($field));
}否则{
返回false;
}
}
函数侧栏\添加\元\框(){
添加元框(
“侧边栏侧边栏”,
__(“侧边栏”、“侧边栏”),
'侧边栏_html',
“第页”,
"先进",,
“默认”
);
}
添加动作(“添加元框”、“侧栏添加元框”);
函数侧栏_html($post){
wp_nonce_字段(“_sidebar_nonce”,“sidebar_nonce”);?>
bočnýstlpec ak bolo treba


您可以使用以下代码

function sidebar_get_meta( $value ) {
    global $post;
    $field = get_post_meta( $post->ID, $value, true );
    if ( ! empty( $field ) ) {
        return is_array( $field ) ? stripslashes_deep( $field ) : stripslashes( wp_kses_decode_entities( $field ) );
    } else {
        return false;
    }
}


function sidebar_add_meta_box() {
    add_meta_box(
        'sidebar-sidebar',
        __( 'sidebar', 'sidebar' ),
        'sidebar_html',
        'page',
        'advanced',
        'default'
    );
}
add_action( 'add_meta_boxes', 'sidebar_add_meta_box' );


function sidebar_html( $post) {
    wp_nonce_field( '_sidebar_nonce', 'sidebar_nonce' ); ?>
    <p>bočný stlpec ak by bolo treba</p>

    <?php
    $content = sidebar_get_meta( 'sidebar_sidebar' );
    $editor_id = 'sidebar_sidebar';

    $settings = array( 
        'media_buttons' => true,
        'quicktags' => true,
        'tinymce' => true,
        'textarea_rows' => 5
    );
    wp_editor( $content, $editor_id, $settings );
}


function sidebar_save( $post_id ) {
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
    if ( ! isset( $_POST['sidebar_nonce'] ) || ! wp_verify_nonce( $_POST['sidebar_nonce'], '_sidebar_nonce' ) ) return;
    if ( ! current_user_can( 'edit_post', $post_id ) ) return;

    if ( isset( $_POST['sidebar_sidebar'] ) )
        update_post_meta( $post_id, 'sidebar_sidebar', stripslashes( $_POST['sidebar_sidebar'] ) );
}
add_action( 'save_post', 'sidebar_save' );
函数侧栏\u get\u meta($value){
全球$员额;
$field=get\u post\u meta($post->ID,$value,true);
如果(!空($field)){
返回是数组($field)?stripslashes_deep($field):stripslashes(wp_kses_decode_entities($field));
}否则{
返回false;
}
}
函数侧栏\添加\元\框(){
添加元框(
“侧边栏侧边栏”,
__(“侧边栏”、“侧边栏”),
'侧边栏_html',
“第页”,
"先进",,
“默认”
);
}
添加动作(“添加元框”、“侧栏添加元框”);
函数侧栏_html($post){
wp_nonce_字段(“_sidebar_nonce”,“sidebar_nonce”);?>
bočnýstlpec ak bolo treba


条纹斜杠代替esc|u attr|great