I created a custom field. Saving to db is OK. But when I save a page, the text is not saved as formatted but with html tags.
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' );
When I save the content, it displays it as follows:
<strong>Lorem ipsum</strong>
dolor sit amet...
It should display it without html tags. Lorem ipsum must be bold.