动态块属性(字符串)中的德语值在数据库中(当它是编辑器时)被错误地编码/保存,但是如果由管理员编辑,则是正确的。
如何复制:
'.$block_attributes['dataTest'].'';
}
function wrong_encoding_dynamic() {
wp_register_script(
'test',
plugins_url( 'testblock.js',__FILE__ ),
array( 'wp-editor', 'wp-i18n', 'wp-element', 'wp-components', 'wp-blocks' ),
'1.0.0',
true
);
register_block_type( 'dev/test', array(
'editor_script' => 'test',
'render_callback' => 'test_callback'
) );
}
add_action( 'init', 'wrong_encoding_dynamic' );testblock.js:
( function( blocks, element, data ) {
var el = element.createElement,
registerBlockType = blocks.registerBlockType;
const {
TextControl,
} = wp.components;
registerBlockType( 'dev/test', {
title: 'Dev: Test',
icon: 'megaphone',
category: 'widgets',
attributes: {
dataTest:{
type:'string',
default:'ÄÖÜäöüß'
},
},
edit: function( props ) {
return el(TextControl,{
onChange: ( value ) => {
props.setAttributes({dataTest:value});
},
}
);
}
});
}(
window.wp.blocks,
window.wp.element,
window.wp.data,
) );例如,db中的post内容:
但应该是:
你知道怎么回事吗?
发布于 2020-10-16 16:44:34
解决它:这是一个兼容性问题。在古腾堡之前的几天里,我们可以用这种方式更新一篇文章:
// get post object by id
$post_obj = get_post($post_id);
// do something with post_content
// unhook this function so it doesn't loop infinitely
remove_action( 'save_post', array($this, 'replace_postcontent') );
// update the post, which calls save_post again
wp_update_post( array( 'ID' => $post_obj->ID, 'post_content' => $post_obj->post_content ) );
// re-hook this function
add_action( 'save_post', array($this, 'replace_postcontent') );它仍然可以工作,但是会引起像上面所描述的问题。解决方案只是使用post对象。而不是:wp_update_post( array( 'ID' => $post_obj->ID, 'post_content' => $post_obj->post_content ) ); use:wp_update_post( $post_obj );
https://wordpress.stackexchange.com/questions/376555
复制相似问题