Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions tests/test-wpml-compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,51 @@ public function test_wpml_compatibility_featured_post() {
$filtered_posts = apply_filters( 'neve_filter_featured_posts', $posts );
$this->assertEquals( $original_post_id, reset($filtered_posts ), 'WPML compatibility should filter posts' );
}

/**
* Theme mod keys registered for translation in wpml-config.xml.
*
* @return list<string>
*/
private function get_wpml_theme_mod_keys(): array {
$config = simplexml_load_file( get_template_directory() . '/wpml-config.xml' );
$this->assertNotFalse( $config, 'wpml-config.xml should be valid XML' );

$keys = [];
foreach ( $config->xpath( '/wpml-config/admin-texts/key[@name="theme_mods_neve"]/key' ) as $key ) {
$keys[] = (string) $key['name'];
}

return $keys;
}

public function test_wpml_config_lists_free_text_theme_mods(): void {
$keys = $this->get_wpml_theme_mod_keys();

$expected = [
\HFG\Core\Components\CustomHtml::COMPONENT_ID . '_' . \HFG\Core\Components\CustomHtml::CONTENT_ID,
// Legacy top bar text, the Custom HTML default on migrated sites.
'neve_top_bar_content',
'footer_copyright_content',
\HFG\Core\Components\Button::COMPONENT_ID . '_' . \HFG\Core\Components\Button::TEXT_ID,
\HFG\Core\Components\Button::COMPONENT_ID . '_' . \HFG\Core\Components\Button::LINK_ID,
\HFG\Core\Components\Search::COMPONENT_ID . '_' . \HFG\Core\Components\Search::PLACEHOLDER_ID,
\HFG\Core\Components\Search::COMPONENT_ID . '_' . \HFG\Core\Components\Utility\SearchIconButton::BUTTON_TEXT,
\HFG\Core\Components\SearchResponsive::COMPONENT_ID . '_' . \HFG\Core\Components\SearchResponsive::PLACEHOLDER_ID,
'neve_metadata_separator',
'neve_single_post_metadata_separator',
'neve_scroll_to_top_label',
];

foreach ( $expected as $key ) {
$this->assertContains( $key, $keys, "wpml-config.xml should register the {$key} theme mod" );
}
}

public function test_wpml_config_omits_theme_mods_the_theme_never_reads(): void {
$keys = $this->get_wpml_theme_mod_keys();

$this->assertNotContains( 'neve_footer_text', $keys );
$this->assertNotContains( 'neve_read_more_text', $keys );
}
}
12 changes: 10 additions & 2 deletions wpml-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,26 @@
</custom-fields>
<admin-texts>
<key name="theme_mods_neve">
<key name="neve_footer_text"/>
<key name="neve_exclusive_products_title"/>
<key name="neve_sale_tag_text"/>
<key name="neve_metadata_separator"/>
<key name="neve_read_more_text"/>

<key name="neve_post_comment_section_title"/>
<key name="neve_post_comment_form_title"/>
<key name="neve_post_comment_form_button_text"/>
<key name="nav-icon_menu_label"/>
<key name="header_search_button_text"/>
<key name="header_palette_switch_placeholder"/>

<key name="custom_html_content"/>
Comment thread
pirate-bot marked this conversation as resolved.
Resolved
<key name="neve_top_bar_content"/>
<key name="footer_copyright_content"/>
<key name="button_base_text_setting"/>
<key name="button_base_link_setting"/>
<key name="header_search_placeholder"/>
<key name="header_search_responsive_placeholder"/>
<key name="neve_single_post_metadata_separator"/>
<key name="neve_scroll_to_top_label"/>
Comment on lines +23 to +31

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note The Custom HTML text is read through the cached Mods::get(). The copyright text calls get_theme_mod() directly. If the cache fills before WPML filters theme_mods_neve, a translated page can still show the default-language HTML. Translate both texts in WPML String Translation on a free-only site. If both show translated on the second-language page, the change is safe. If Custom HTML stays in the default language, the cached read bypasses the translation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The concern is unfounded. custom_html_content is retrieved only during template rendering through component_setting( CustomHtml::CONTENT_ID ) in component-html.php#L15. This happens well after WPML registers its option_theme_mods_neve filter during plugins_loaded. Since there are no earlier reads during theme initialization, Mods::$_cached is still empty when the component renders. Therefore, Mods::get() calls get_theme_mod(), which correctly passes through WPML’s active translation filter.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, and I withdraw this note. Mods::get() caches per key, not the whole theme-mods array (inc/core/settings/mods.php:51-56). The only read of custom_html_content is at template render (component-html.php:15). An earlier call on after_setup_theme reads the custom colors key (inc/core/front_end.php:151-174). Other keys read earlier cannot prefill the Custom HTML value.

</key>
</admin-texts>
</wpml-config>
Loading