Skip to content

Commit 36ffb76

Browse files
Merge pull request #549 from Smartling/WP-913-quotes
add option to skip ACF filter removal (WP-913)
2 parents aa5c917 + 96fcb20 commit 36ffb76

9 files changed

Lines changed: 61 additions & 5 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "smartling/wordpress-connector",
33
"license": "GPL-2.0-or-later",
4-
"version": "3.9.14",
4+
"version": "3.9.15",
55
"description": "",
66
"type": "wordpress-plugin",
77
"repositories": [

inc/Smartling/Bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ public function updateGlobalExpertSettings(): void
191191
GlobalSettingsManager::setAddSlashesBeforeSavingContent($data[GlobalSettingsManager::SETTING_ADD_SLASHES_BEFORE_SAVING_CONTENT]);
192192
GlobalSettingsManager::setAddSlashesBeforeSavingMeta($data[GlobalSettingsManager::SETTING_ADD_SLASHES_BEFORE_SAVING_META]);
193193
GlobalSettingsManager::setCustomDirectives($data[GlobalSettingsManager::SETTING_CUSTOM_DIRECTIVES]);
194+
GlobalSettingsManager::setRemoveAcfParseSaveBlocksFilter($data[GlobalSettingsManager::SETTING_REMOVE_ACF_PARSE_SAVE_BLOCKS_FILTER]);
194195
GlobalSettingsManager::setSkipSelfCheck((int)$data['selfCheckDisabled']);
195196
GlobalSettingsManager::setDisableLogging((int)$data['disableLogging']);
196197
GlobalSettingsManager::setLogFileSpec($data['loggingPath']);

inc/Smartling/DbAl/WordpressContentEntities/PostEntityStd.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,14 @@ public function set(Entity $entity): int
203203
}
204204
$array = $entity->toArray();
205205
$array['post_category'] = \wp_get_post_categories($entity->ID);
206-
// ACF would replace our properly escaped content with its own escaping.
207-
remove_action('content_save_pre', 'acf_parse_save_blocks', 5);
206+
207+
if (GlobalSettingsManager::isRemoveAcfParseSaveBlocksFilter()) {
208+
// ACF would replace our properly escaped content with its own escaping.
209+
$result = remove_action('content_save_pre', 'acf_parse_save_blocks', 5);
210+
$this->getLogger()->debug("Remove ACF parse save blocks filter, result=" . ($result ? '1' : '0'));
211+
} else {
212+
$this->getLogger()->info("Skip remove ACF parse save blocks filter");
213+
}
208214

209215
/**
210216
* Content expected to be slashed for
@@ -225,6 +231,8 @@ public function set(Entity $entity): int
225231
$addSlashes ? '1' : '0',
226232
$this->wordpressFunctionProxyHelper->get_current_blog_id(),
227233
));
234+
$preSavePostContent = $array['post_content'];
235+
$this->getLogger()->debug("Base64Encoded post content: " . base64_encode($array['post_content']));
228236
$res = wp_insert_post($array, true);
229237
if (is_wp_error($res) || 0 === $res) {
230238
$msg = vsprintf('An error had happened while saving post : \'%s\'', [\json_encode($array)]);
@@ -236,6 +244,11 @@ public function set(Entity $entity): int
236244
$this->getLogger()->error($msg);
237245
throw new SmartlingDataUpdateException($msg);
238246
}
247+
$afterSavePostContent = get_post_field('post_content', $res, 'raw');
248+
if (stripslashes($preSavePostContent) !== $afterSavePostContent) {
249+
$this->getLogger()->warning("Retrieved post content after saving is not as expected: ")
250+
. base64_encode($afterSavePostContent);
251+
}
239252

240253
return (int)$res;
241254
}

inc/Smartling/Services/GlobalSettingsManager.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,23 @@ public static function setFilterUiVisible(int $value): void
205205
}
206206
}
207207

208+
public const SETTING_REMOVE_ACF_PARSE_SAVE_BLOCKS_FILTER = 'smartling_remove_acf_parse_save_blocks_filter';
209+
public const SETTING_REMOVE_ACF_PARSE_SAVE_BLOCKS_FILTER_DEFAULT = "1";
210+
211+
public static function isRemoveAcfParseSaveBlocksFilter(): bool
212+
{
213+
return SimpleStorageHelper::get(self::SETTING_REMOVE_ACF_PARSE_SAVE_BLOCKS_FILTER, self::SETTING_REMOVE_ACF_PARSE_SAVE_BLOCKS_FILTER_DEFAULT) === "1";
214+
}
215+
216+
public static function setRemoveAcfParseSaveBlocksFilter(string $value): void
217+
{
218+
if ($value === self::SETTING_REMOVE_ACF_PARSE_SAVE_BLOCKS_FILTER_DEFAULT) {
219+
SimpleStorageHelper::drop(self::SETTING_REMOVE_ACF_PARSE_SAVE_BLOCKS_FILTER);
220+
} else {
221+
SimpleStorageHelper::set(self::SETTING_REMOVE_ACF_PARSE_SAVE_BLOCKS_FILTER, $value);
222+
}
223+
}
224+
208225
public const SETTING_ADD_SLASHES_BEFORE_SAVING_CONTENT = 'smartling_add_slashes_before_saving_content';
209226
public const SETTING_ADD_SLASHES_BEFORE_SAVING_CONTENT_DEFAULT = "1";
210227

inc/Smartling/WP/View/ConfigurationProfiles.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,26 @@ class="toggleExpert"><strong><?= __('Show Expert Settings'); ?></strong></a>
266266
?>
267267
</td>
268268
</tr>
269+
<tr>
270+
<th><label for="<?= GlobalSettingsManager::SETTING_REMOVE_ACF_PARSE_SAVE_BLOCKS_FILTER?>"><?= __('Remove ACF parse save blocks filter')?></label></th>
271+
<td>
272+
<?=
273+
HtmlTagGeneratorHelper::tag(
274+
'select',
275+
HtmlTagGeneratorHelper::renderSelectOptions(
276+
GlobalSettingsManager::isRemoveAcfParseSaveBlocksFilter() ? 1 : 0,
277+
[
278+
0 => 'No',
279+
1 => 'Yes',
280+
]),
281+
[
282+
'id' => GlobalSettingsManager::SETTING_REMOVE_ACF_PARSE_SAVE_BLOCKS_FILTER,
283+
'name' => GlobalSettingsManager::SETTING_REMOVE_ACF_PARSE_SAVE_BLOCKS_FILTER,
284+
]
285+
)
286+
?>
287+
</td>
288+
</tr>
269289
<tr>
270290
<th><label for="<?= GlobalSettingsManager::SETTING_CUSTOM_DIRECTIVES?>"><a href="https://help.smartling.com/hc/en-us/articles/360008000893-XML#directives"><?= __('Custom directives')?></a><?= __('. The connector will wrap each line from this text area into inline directives') ?><pre>&lt;!-- smartling.%%line%% --&gt;</pre><br><?= __('Invalid directives WILL BREAK PROCESSING.')?></label></th>
271291
<td>

js/configuration-profile-form.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
'smartling_add_slashes_before_saving_content': $('#smartling_add_slashes_before_saving_content').val(),
2626
'smartling_add_slashes_before_saving_meta': $('#smartling_add_slashes_before_saving_meta').val(),
2727
'smartling_custom_directives': $('#smartling_custom_directives').val(),
28+
'smartling_remove_acf_parse_save_blocks_filter': $('#smartling_remove_acf_parse_save_blocks_filter').val(),
2829
'selfCheckDisabled': $('#selfCheckDisabled').val(),
2930
'disableLogging': $('#disableLogging').val(),
3031
'loggingPath': $('#loggingPath').val(),

readme.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: translation, localization, localisation, translate, multilingual, smartlin
44
Requires at least: 5.5
55
Tested up to: 6.6.2
66
Requires PHP: 8.0
7-
Stable tag: 3.9.14
7+
Stable tag: 3.9.15
88
License: GPLv2 or later
99

1010
Translate content in WordPress quickly and seamlessly with Smartling, the industry-leading Translation Management System.
@@ -62,6 +62,9 @@ Additional information on the Smartling Connector for WordPress can be found [he
6262
3. Track translation status within WordPress from the Submissions Board. View overall progress of submitted translation requests as well as resend updated content.
6363

6464
== Changelog ==
65+
= 3.9.15 =
66+
* Add expert setting to skip ACF filter `acf_parse_save_blocks` removal. Defaults to on.
67+
6568
= 3.9.14 =
6669
* Remove excessive logging
6770

smartling-connector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Plugin Name: Smartling Connector
1212
* Plugin URI: https://www.smartling.com/products/automate/integrations/wordpress/
1313
* Description: Integrate your WordPress site with Smartling to upload your content and download translations.
14-
* Version: 3.9.14
14+
* Version: 3.9.15
1515
* Author: Smartling
1616
* Author URI: https://www.smartling.com
1717
* License: GPL-2.0+

tests/Mocks/WordpressFunctionsMockHelper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ function add_filter($action, $handler)
233233
if (!function_exists('remove_action')) {
234234
function remove_action($tag, $function_to_remove, $priority = 10)
235235
{
236+
return false;
236237
}
237238
}
238239

0 commit comments

Comments
 (0)