Wordpress 自定义所见即所得文本区域-html文本格式
我创建了一个自定义字段。保存到db是可以的。但是当我保存一个页面时,文本不是以格式化的形式保存的,而是用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
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