From 043704cb80aa23ee298578e7a4f1ee8712b8b320 Mon Sep 17 00:00:00 2001 From: vsolovei-smartling Date: Thu, 2 Apr 2026 19:02:29 +0200 Subject: [PATCH] add elementor gallery support (WP-997) Co-Authored-By: Claude Sonnet 4.6 --- .claude/skills/bump-version/SKILL.md | 10 +++ composer.json | 2 +- .../Elementor/Elements/Gallery.php | 63 ++++++++++++++ readme.txt | 5 +- smartling-connector.php | 2 +- .../ContentTypes/Elementor/GalleryTest.php | 84 +++++++++++++++++++ .../ExternalContentElementorTest.php | 10 +++ 7 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 .claude/skills/bump-version/SKILL.md create mode 100644 inc/Smartling/ContentTypes/Elementor/Elements/Gallery.php create mode 100644 tests/Smartling/ContentTypes/Elementor/GalleryTest.php diff --git a/.claude/skills/bump-version/SKILL.md b/.claude/skills/bump-version/SKILL.md new file mode 100644 index 00000000..52994878 --- /dev/null +++ b/.claude/skills/bump-version/SKILL.md @@ -0,0 +1,10 @@ +--- +name: bump-version +description: Increase version number +--- + +1. Examine changes in the current git branch compared to master. +2. Decide if changes are minor, major or patch. +3. Update the smartling-connector.php comment that starts with `Version:` with the new version number. +4. Update the composer.json version with the new version number. +5. Update the readme.txt `Stable tag:` with the new version number and add the release notes. diff --git a/composer.json b/composer.json index 0d6aa707..0e0a0f91 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "smartling/wordpress-connector", "license": "GPL-2.0-or-later", - "version": "5.3.2", + "version": "5.3.3", "description": "", "type": "wordpress-plugin", "repositories": [ diff --git a/inc/Smartling/ContentTypes/Elementor/Elements/Gallery.php b/inc/Smartling/ContentTypes/Elementor/Elements/Gallery.php new file mode 100644 index 00000000..27f1ea19 --- /dev/null +++ b/inc/Smartling/ContentTypes/Elementor/Elements/Gallery.php @@ -0,0 +1,63 @@ +settings['gallery'] ?? [] as $index => $listItem) { + $key = "gallery/$index/id"; + $id = $this->getIntSettingByKey($key, $this->settings); + if ($id !== null) { + $return->addContent(new Content($id, ContentTypeHelper::POST_TYPE_ATTACHMENT), $this->id, "settings/$key"); + } + } + + return $return; + } + + public function getTranslatableStrings(): array + { + $return = []; + foreach ($this->settings['galleries'] ?? [] as $gallery) { + $id = $gallery['_id'] ?? null; + if ($id !== null && array_key_exists('gallery_title', $gallery)) { + $return['galleries/' . $id]['gallery_title'] = $gallery['gallery_title']; + } + } + + return [$this->getId() => $return]; + } + + public function setTargetContent(ExternalContentElementor $externalContentElementor, RelatedContentInfo $info, array $strings, SubmissionEntity $submission): static + { + foreach ($strings[$this->id] ?? [] as $array) { + if (is_array($array)) { + foreach ($array as $id => $values) { + foreach ($this->settings['galleries'] ?? [] as $index => $gallery) { + if (($gallery['_id'] ?? '') === $id) { + foreach ($values as $property => $value) { + $this->settings['galleries'][$index][$property] = $value; + } + } + } + } + } + } + $this->raw['settings'] = $this->settings; + + return new static($this->raw); + } +} diff --git a/readme.txt b/readme.txt index c95506eb..6ac1193b 100755 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: translation, localization, multilingual, internationalization, smartling Requires at least: 5.5 Tested up to: 6.9 Requires PHP: 8.0 -Stable tag: 5.3.2 +Stable tag: 5.3.3 License: GPLv2 or later 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 3. Track translation status within WordPress from the Submissions Board. View overall progress of submitted translation requests as well as resend updated content. == Changelog == += 5.3.3 = +* Added support for Elementor gallery widget + = 5.3.2 = * Added support for Elementor nested accordion widget diff --git a/smartling-connector.php b/smartling-connector.php index a3b304d0..1abef387 100755 --- a/smartling-connector.php +++ b/smartling-connector.php @@ -11,7 +11,7 @@ * Plugin Name: Smartling Connector * Plugin URI: https://www.smartling.com/products/automate/integrations/wordpress/ * Description: Integrate your WordPress site with Smartling to upload your content and download translations. - * Version: 5.3.2 + * Version: 5.3.3 * Author: Smartling * Author URI: https://www.smartling.com * License: GPL-2.0+ diff --git a/tests/Smartling/ContentTypes/Elementor/GalleryTest.php b/tests/Smartling/ContentTypes/Elementor/GalleryTest.php new file mode 100644 index 00000000..0edb9cac --- /dev/null +++ b/tests/Smartling/ContentTypes/Elementor/GalleryTest.php @@ -0,0 +1,84 @@ + '14d5abc', + 'elType' => 'widget', + 'widgetType' => 'gallery', + 'settings' => $settings, + 'elements' => [], + ]); + } + + public function testRelated(): void + { + $imageSourceId = 21162; + $imageTargetId = 31162; + + $externalContentElementor = $this->createMock(ExternalContentElementor::class); + $externalContentElementor->method('getTargetId') + ->with(0, $imageSourceId, 0, ContentTypeHelper::POST_TYPE_ATTACHMENT)->willReturn($imageTargetId); + + $this->assertEquals( + $imageTargetId, + $this->makeWidget(['gallery' => [ + ['id' => 21161, 'url' => 'https://example.com/1.webp'], + ['id' => $imageSourceId, 'url' => 'https://example.com/2.webp'], + ['id' => 21163, 'url' => 'https://example.com/3.webp'], + ]]) + ->setRelations( + new Content($imageSourceId, ContentTypeHelper::POST_TYPE_ATTACHMENT), + $externalContentElementor, + 'settings/gallery/1/id', + $this->createMock(SubmissionEntity::class), + )->toArray()['settings']['gallery'][1]['id'], + ); + } + + public function testGetTranslatableStrings(): void + { + $strings = $this->makeWidget(['galleries' => [ + ['gallery_title' => 'New Gallery', '_id' => '04c68ec'], + ['gallery_title' => 'Second Gallery', '_id' => 'ab12345'], + ]])->getTranslatableStrings(); + + $this->assertEquals('New Gallery', $strings['14d5abc']['galleries/04c68ec']['gallery_title']); + $this->assertEquals('Second Gallery', $strings['14d5abc']['galleries/ab12345']['gallery_title']); + } + + public function testSetTargetContent(): void + { + $result = $this->makeWidget(['galleries' => [ + ['gallery_title' => 'New Gallery', '_id' => '04c68ec'], + ['gallery_title' => 'Second Gallery', '_id' => 'ab12345'], + ]])->setTargetContent( + $this->createMock(ExternalContentElementor::class), + new RelatedContentInfo([]), + [ + '14d5abc' => [ + 'galleries' => [ + '04c68ec' => ['gallery_title' => 'Translated Gallery'], + 'ab12345' => ['gallery_title' => 'Translated Second'], + ], + ], + ], + $this->createMock(SubmissionEntity::class), + )->toArray(); + + $this->assertEquals('Translated Gallery', $result['settings']['galleries'][0]['gallery_title']); + $this->assertEquals('Translated Second', $result['settings']['galleries'][1]['gallery_title']); + } +} diff --git a/tests/Smartling/ContentTypes/ExternalContentElementorTest.php b/tests/Smartling/ContentTypes/ExternalContentElementorTest.php index ad69e885..ba13c117 100644 --- a/tests/Smartling/ContentTypes/ExternalContentElementorTest.php +++ b/tests/Smartling/ContentTypes/ExternalContentElementorTest.php @@ -323,6 +323,16 @@ public function extractElementorDataProvider(): array ['abc123/text' => 'Click Me'], [ContentTypeHelper::POST_TYPE_ATTACHMENT => [789]], ], + 'gallery widget' => [ + '[{"id":"14d5abc","elType":"widget","settings":{"gallery":[{"id":21161,"url":"https://example.com/1.webp"},{"id":21162,"url":"https://example.com/2.webp"}],"galleries":[{"gallery_title":"New Gallery","_id":"04c68ec"}]},"elements":[],"widgetType":"gallery"}]', + ['14d5abc/galleries/04c68ec/gallery_title' => 'New Gallery'], + [ContentTypeHelper::POST_TYPE_ATTACHMENT => [21161, 21162]], + ], + 'nested accordion with svg icons' => [ + '[{"id":"cf8c5a0","elType":"widget","settings":{"accordion_item_title_icon":{"value":{"url":"https://example.com/plus.svg","id":329},"library":"svg"},"accordion_item_title_icon_active":{"value":{"url":"https://example.com/minus.svg","id":330},"library":"svg"}},"elements":[],"widgetType":"nested-accordion"}]', + [], + [ContentTypeHelper::POST_TYPE_ATTACHMENT => [329, 330]], + ], 'dynamic content in elements' => [ file_get_contents(__DIR__ . '/wp-975.json'), [],