I have problem with encoding on saving custom post type in Wordpress. When I hit update, the UTF-8 characters (č, š, ž, ø, etc.) are tranformed to "u010d" and others.
The problem seems to be with form. I recieve already broken characters through POST.
I have saved file with UTF-8 encoding and I have meta tag for encoding in HEAD of HTML.
What can I do to fix this?
Thank you!
Edit:
I have accept-charset="UTF-8"
in form.
HEAD: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Function:
add_action( 'save_post', 'layered_images_save_info' );
function layered_images_save_info( $post_id ) {
// verify nonce
if ( ! wp_verify_nonce( $_POST['layered_images_box_nonce'], basename( __FILE__ ) ) ) {
return $post_id;
}
// check autosave
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
return $post_id;
}
// check permissions
if ( 'layered_images' == $_POST[ 'post_type'] && current_user_can( 'edit_post', $post_id ) ) {
/* Save Slider Images */
//echo "";print_r($_POST['gallery_img']);exit;
//$bla = html_entity_decode($_POST[ 'layer_titles' ], ENT_QUOTES, "utf-8");
$gallery_images = ( isset( $_POST[ 'gallery_img' ] ) ? $_POST[ 'gallery_img' ] : '' );
$layer_opacity = ( isset( $_POST[ 'layer_opacity' ] ) ? $_POST[ 'layer_opacity' ] : '' );
$layer_color = ( isset( $_POST[ 'layer_color' ] ) ? $_POST[ 'layer_color' ] : '' );
//print_r($bla);exit;
$gallery_images = strip_tags( json_encode( $gallery_images ) );
$visible_layers = ( isset( $_POST[ 'visible_layers' ] ) ? $_POST[ 'visible_layers' ] : '' );
$visible_layers = strip_tags( json_encode( $visible_layers ) );
$visible_user_layers = ( isset( $_POST[ 'visible_user_layers' ] ) ? $_POST[ 'visible_user_layers' ] : '' );
$visible_user_layers = strip_tags( json_encode( $visible_user_layers ) );
$layer_titles = ( isset( $_POST[ 'layer_titles' ] ) ? $_POST[ 'layer_titles' ] : '' );
$layer_titles = json_encode( $layer_titles ) ;
update_post_meta( $post_id, "_layer_gallery_images", $gallery_images );
update_post_meta( $post_id, "_layer_visible_layers", $visible_layers );
update_post_meta( $post_id, "_visible_user_layers", $visible_user_layers );
update_post_meta( $post_id, "_layer_titles", $layer_titles );
update_post_meta( $post_id, "_layer_opacity", $layer_opacity );
update_post_meta( $post_id, "_layer_color", $layer_color );
} else {
return $post_id;
}
}