Skip to content

Commit

Permalink
Merge pull request #5 from Bynder/bug/FSB-6124
Browse files Browse the repository at this point in the history
[FSB-6124] Short Codes from WP are pushed as their rendered version to GC
  • Loading branch information
CWDN authored May 21, 2024
2 parents 8aa54ee + 7075eab commit 47b5254
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion includes/classes/sync/push.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ public function maybe_do_item_update( $update ) {
);
}

if ($result === false) {
wp_send_json_error( 'Failed to push content to Content Workflow' );
}

return $result;
}

Expand Down Expand Up @@ -556,7 +560,12 @@ protected function set_post_field_value( $post_column ) {
case 'post_excerpt':
$el_value = wp_kses_post( $this->get_element_value() );
if ( 'post_content' === $post_column ) {
$value = apply_filters( 'the_content', $value );
$value = $this->ensureShortcodesAreNotConvertedToHtml(
function ($value) {
return apply_filters( 'the_content', $value );
},
$value
);
}

// There are super minor encoding issues we want to ignore.
Expand All @@ -577,6 +586,41 @@ protected function set_post_field_value( $post_column ) {
return $updated;
}

private function ensureShortcodesAreNotConvertedToHtml(callable $callback, string $value): string
{
preg_match_all(
'/\[[\w\W]+?\]/',
$value,
$matches
);

foreach ($matches[0] as $match) {
$value = str_replace(
$match,
'<shortcode>' . base64_encode($match) . '</shortcode>',
$value
);
}

$value = $callback($value);

preg_match_all(
'/<shortcode>([\w\W])+?<\/shortcode>/',
$value,
$matches
);

foreach ($matches[0] as $match) {
$value = str_replace(
$match,
base64_decode(strip_tags($match)),
$value
);
}

return $value;
}

/**
* Sets the item config element value for WP taxonomy terms,
* if it is determeined that the value changed.
Expand Down

0 comments on commit 47b5254

Please sign in to comment.