Distributed post have broken accents
When distributing a post that consists of some diacritical characters the pushed version seems to have them converted to unicode and removed the slashes. I cannot find the proper place where this may take place.
The content is edited via Elementor. Distributed to multisite website (different domain).
What is weird is that sometimes this happens but sometimes it pushes the content correctly.
Example:

@markusvisse we're looking at some broad updates to how Distributor handles push vs. pull, internal vs. external connections, and integrations with page builders like Elementor as part of our 2.0.0 release. I'm slating your issue for the release after that to give us time for further testing, but if there's any further details you can share about your setup (multisite vs. multiple WP instances, WP version, etc.) then that'll help us triage... thanks!
As I wrote it's a mutisite installation based on different domains. WP is up to date. Is there anything that may convert those characters into unicode and remove the slash while hitting "Distribute" or while synchronizing post?
I've sorted this out myself. While updating meta field there was a function breaking the encoding for content. Had to add an if statement for elementor data to convert from unicode to utf-8.
@markusvisse is that edit you made within Distributor's code or Elementor's? I'm sure either project would appreciate details on what was changed to see about getting that onto their respective roadmap/plugin if you're able to share.
@jeffpaul It was in Distributor itself. Exactly what I've done was:
if ($meta_key == '_elementor_data') {
$meta_value = preg_replace("/\\\\[uU]([0-9A-Fa-f]{4})/", "&#x$1;", $meta_value);
$meta_value = preg_replace("/\\\\[n]/", "", $meta_value);
$meta_value = serialize_corrector($meta_value );
}
Inserted in includes/utils.php right after:
if (!in_array($meta_key, $blacklisted_meta, true)) {
of prepare_meta() function.
It uses:
function serialize_corrector($serialized_string) {
// at first, check if "fixing" is really needed at all. After that, security checkup.
if (@unserialize($serialized_string) !== true && preg_match('/^[aOs]:/', $serialized_string)) {
$serialized_string = preg_replace_callback('/s\:(\d+)\:\"(.*?)\";/s', function($matches) {
return 's:' . strlen($matches[2]) . ':"' . $matches[2] . '";';
}, $serialized_string);
}
return $serialized_string;
}
to fix serialization issue after changing elementor string. Credits for this function to T.Todua here: https://stackoverflow.com/a/38890855/8037971
After this change elementor publishes without any issues when using accents as well as newlines (it also broke \n into regular n characters).
Hope it helps anyone.
@markusvisse I came across the same problem: When using Distributor on an Elementor post, the meta data (that's where Elementor stores its layout) got corrupted ("un-slashed"). This leads to all special characters being corrupted on the frontend. When researching that symptom I came across a similar issue of a different plugin: https://github.com/pods-framework/pods/issues/5040 The most important take-away seems to be:
update_metadata() will unconditionally unslash the meta value passed in, so $meta_value is expected to be wp_slashed first, despite the misleading docs caveat for $meta_value: "this should be raw as opposed to sanitized for database queries"
So my fix was to patch distributor-stable/includes/util.php:set_meta() to explicitly $meta_value = wp_slash($meta_value) before calling update_post_meta() or add_post_meta() (because both internally use update_metadata() which unslashes the value).
Hope this helps!
Add to the includes/utils.php function prepare_post( $post this row $post->post_content = wp_slash($post->post_content);
/**
- Setup additional properties on a post object to enable them to be
- fetched once and manipulated by filters. *
- @param WP_Post $post WP_Post object.
- @since 1.2.2
- @return WP_Post */ function prepare_post( $post ) { $post->link = get_permalink( $post->ID ); $post->meta = prepare_meta( $post->ID ); $post->terms = prepare_taxonomy_terms( $post->ID ); $post->media = prepare_media( $post->ID ); $post->post_content = wp_slash($post->post_content); return $post; }