diff --git a/.wp-env.json b/.wp-env.json index 8c81de8..52d2bfa 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -1,6 +1,6 @@ { "$schema": "https://schemas.wp.org/trunk/wp-env.json", - "core": "https://wordpress.org/wordpress-6.9.6.zip", + "core": "https://wordpress.org/wordpress-7.0.4.zip", "phpVersion": "8.3", "autoPort": false, "port": 8888, diff --git a/blocks/featured-stories/block.json b/blocks/featured-stories/block.json index e189c95..b38c9a5 100644 --- a/blocks/featured-stories/block.json +++ b/blocks/featured-stories/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/featured-stories", - "version": "0.4.3", + "version": "0.4.4", "title": "Featured Stories", "category": "theme", "description": "A sticky-led selection of topic-diverse stories.", diff --git a/blocks/footer-content/block.json b/blocks/footer-content/block.json index 613b519..d7cc2db 100644 --- a/blocks/footer-content/block.json +++ b/blocks/footer-content/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/footer-content", - "version": "0.4.3", + "version": "0.4.4", "title": "CHRNX Footer Content", "category": "theme", "description": "Display translated internal footer navigation and site credit.", diff --git a/blocks/header-tools/block.json b/blocks/header-tools/block.json index 975e12f..46bda30 100644 --- a/blocks/header-tools/block.json +++ b/blocks/header-tools/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/header-tools", - "version": "0.4.3", + "version": "0.4.4", "title": "CHRNX Header Tools", "category": "theme", "description": "Display translated primary navigation and progressive site search.", diff --git a/blocks/journal-link/block.json b/blocks/journal-link/block.json index 38f2c51..64c4f9c 100644 --- a/blocks/journal-link/block.json +++ b/blocks/journal-link/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/journal-link", - "version": "0.4.3", + "version": "0.4.4", "title": "Journal Link", "category": "theme", "description": "Display a translated portable link to the full Journal.", diff --git a/blocks/journal-stream/block.json b/blocks/journal-stream/block.json index b3f6436..7c2f728 100644 --- a/blocks/journal-stream/block.json +++ b/blocks/journal-stream/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/journal-stream", - "version": "0.4.3", + "version": "0.4.4", "title": "Journal Stream", "category": "theme", "description": "The filterable chronological journal.", diff --git a/blocks/latest-podcast/block.json b/blocks/latest-podcast/block.json index f46aa8d..aa67bd1 100644 --- a/blocks/latest-podcast/block.json +++ b/blocks/latest-podcast/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/latest-podcast", - "version": "0.4.3", + "version": "0.4.4", "title": "Latest Podcast", "category": "theme", "description": "A linked card for the latest podcast episode.", diff --git a/blocks/mobile-menu-toggle/block.json b/blocks/mobile-menu-toggle/block.json index 72f5b8e..e5c6e30 100644 --- a/blocks/mobile-menu-toggle/block.json +++ b/blocks/mobile-menu-toggle/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/mobile-menu-toggle", - "version": "0.4.3", + "version": "0.4.4", "title": "CHRNX Mobile Menu Toggle", "category": "theme", "description": "Progressively reveal the primary navigation on small screens.", diff --git a/blocks/podcast-meta/block.json b/blocks/podcast-meta/block.json index 2149421..5693ccd 100644 --- a/blocks/podcast-meta/block.json +++ b/blocks/podcast-meta/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/podcast-meta", - "version": "0.4.3", + "version": "0.4.4", "title": "Podcast Metadata", "category": "theme", "description": "Safe episode details for the current post.", diff --git a/blocks/reading-time/block.json b/blocks/reading-time/block.json index 87bc07b..0872e15 100644 --- a/blocks/reading-time/block.json +++ b/blocks/reading-time/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/reading-time", - "version": "0.4.3", + "version": "0.4.4", "title": "Reading Time", "category": "theme", "description": "Display a localized estimate based on the current post content.", diff --git a/blocks/related-posts/block.json b/blocks/related-posts/block.json index b3ed913..d9430c4 100644 --- a/blocks/related-posts/block.json +++ b/blocks/related-posts/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/related-posts", - "version": "0.4.3", + "version": "0.4.4", "title": "Related Posts", "category": "theme", "description": "Related stories selected by topic, tags, and recency.", diff --git a/blocks/release-detail/block.json b/blocks/release-detail/block.json index 02afd90..20eabf4 100644 --- a/blocks/release-detail/block.json +++ b/blocks/release-detail/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/release-detail", - "version": "0.4.3", + "version": "0.4.4", "title": "Release Detail", "category": "theme", "description": "Album cover, listening links, and the ordered tracklist.", diff --git a/blocks/release-list/block.json b/blocks/release-list/block.json index d356bab..048027d 100644 --- a/blocks/release-list/block.json +++ b/blocks/release-list/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/release-list", - "version": "0.4.3", + "version": "0.4.4", "title": "Release List", "category": "theme", "description": "The No Names releases, each linking to its album page.", diff --git a/blocks/selected-work/block.json b/blocks/selected-work/block.json index f76b64d..19a0deb 100644 --- a/blocks/selected-work/block.json +++ b/blocks/selected-work/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/selected-work", - "version": "0.4.3", + "version": "0.4.4", "title": "Selected Work", "category": "theme", "description": "Hand-picked projects first, then the most recent ones.", diff --git a/blocks/show-links/block.json b/blocks/show-links/block.json index 87e1d05..ef1a218 100644 --- a/blocks/show-links/block.json +++ b/blocks/show-links/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/show-links", - "version": "0.4.3", + "version": "0.4.4", "title": "Show Links", "category": "theme", "description": "Where a podcast show can be listened to, rendered only when a URL exists.", diff --git a/blocks/site-brand/block.json b/blocks/site-brand/block.json index 26b6a5e..fad54b0 100644 --- a/blocks/site-brand/block.json +++ b/blocks/site-brand/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/site-brand", - "version": "0.4.3", + "version": "0.4.4", "title": "CHRNX Site Brand", "category": "theme", "description": "Display the local CHRNX wordmark linked to the site home.", diff --git a/blocks/subscribe-cta/block.json b/blocks/subscribe-cta/block.json index 3255227..03b0feb 100644 --- a/blocks/subscribe-cta/block.json +++ b/blocks/subscribe-cta/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/subscribe-cta", - "version": "0.4.3", + "version": "0.4.4", "title": "Subscribe CTA", "category": "theme", "description": "A call to action linked to the configured subscribe page.", diff --git a/blocks/subscribe-form/block.json b/blocks/subscribe-form/block.json index e86f467..fb3269c 100644 --- a/blocks/subscribe-form/block.json +++ b/blocks/subscribe-form/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/subscribe-form", - "version": "0.4.3", + "version": "0.4.4", "title": "Subscribe Form", "category": "theme", "description": "The email subscription form, rendered only when a provider endpoint is configured.", diff --git a/blocks/theme-toggle/block.json b/blocks/theme-toggle/block.json index 1228f2d..ce574c5 100644 --- a/blocks/theme-toggle/block.json +++ b/blocks/theme-toggle/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/theme-toggle", - "version": "0.4.3", + "version": "0.4.4", "title": "Theme Toggle", "category": "theme", "description": "Choose a light, dark, or system color theme.", diff --git a/blocks/topic-hero/block.json b/blocks/topic-hero/block.json index 067fe1d..9746f35 100644 --- a/blocks/topic-hero/block.json +++ b/blocks/topic-hero/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/topic-hero", - "version": "0.4.3", + "version": "0.4.4", "title": "Topic Hero", "category": "theme", "description": "A fixed-art hero for an editorial topic.", diff --git a/blocks/track-meta/block.json b/blocks/track-meta/block.json index 1a843b3..3c18c18 100644 --- a/blocks/track-meta/block.json +++ b/blocks/track-meta/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/track-meta", - "version": "0.4.3", + "version": "0.4.4", "title": "Track Meta", "category": "theme", "description": "Player, listening links, and album for one song.", diff --git a/functions.php b/functions.php index 7c977d8..6bc4749 100644 --- a/functions.php +++ b/functions.php @@ -1,5 +1,5 @@ 'en-US', + 'es' => 'es-MX', + ); + + $slug = ''; + + if ( is_singular( 'post' ) ) { + // A post carries one language; extra terms are an editing mistake. + $terms = get_the_terms( get_queried_object_id(), 'chrnx_language' ); + $slug = ( is_array( $terms ) && isset( $terms[0]->slug ) ) ? $terms[0]->slug : ''; + } elseif ( is_tax( 'chrnx_language' ) ) { + $term = get_queried_object(); + $slug = $term instanceof WP_Term ? $term->slug : ''; + } + + return $locales[ $slug ] ?? ''; +} + +/** + * Apply the editorial language to the html element. + * + * @param string $output Attribute string built by core. + * @return string Attribute string carrying the editorial language. + */ +function chrnx_filter_language_attributes( $output ) { + $locale = chrnx_get_document_locale(); + + if ( '' === $locale ) { + return $output; + } + + // Replace only the language, so dir and any plugin attribute survive. + return preg_replace( '/lang="[^"]*"/', 'lang="' . esc_attr( $locale ) . '"', (string) $output, 1 ); +} +add_filter( 'language_attributes', 'chrnx_filter_language_attributes' ); + /** * Print Open Graph and Twitter card tags only when nothing else does. * diff --git a/style.css b/style.css index 588030e..353d4e3 100644 --- a/style.css +++ b/style.css @@ -3,6 +3,6 @@ Theme Name: CHRNX Description: A native block theme for chrnx.dev. Requires at least: 6.9 Requires PHP: 8.1 -Version: 0.4.3 +Version: 0.4.4 Text Domain: chrnx */ diff --git a/tests/php/ThemeSetupTest.php b/tests/php/ThemeSetupTest.php index 5c29bf9..0c3e82b 100644 --- a/tests/php/ThemeSetupTest.php +++ b/tests/php/ThemeSetupTest.php @@ -37,6 +37,83 @@ class ThemeSetupTest extends WP_UnitTestCase { $this->assertContains( 'assets/css/components.css', $editor_styles ); } + /** + * Ensure a Spanish post declares a Spanish document language. + */ + public function test_language_attributes_follow_a_spanish_post() { + $post_id = self::factory()->post->create(); + wp_set_object_terms( $post_id, 'es', 'chrnx_language' ); + + $this->go_to( get_permalink( $post_id ) ); + + $this->assertTrue( is_singular( 'post' ) ); + $this->assertSame( 'lang="es-MX"', chrnx_filter_language_attributes( 'lang="en-US"' ) ); + } + + /** + * Ensure an English post keeps the English document language. + */ + public function test_language_attributes_follow_an_english_post() { + $post_id = self::factory()->post->create(); + wp_set_object_terms( $post_id, 'en', 'chrnx_language' ); + + $this->go_to( get_permalink( $post_id ) ); + + $this->assertSame( 'lang="en-US"', chrnx_filter_language_attributes( 'lang="en-US"' ) ); + } + + /** + * Ensure the direction attribute survives the language swap. + */ + public function test_language_attributes_preserve_other_attributes() { + $post_id = self::factory()->post->create(); + wp_set_object_terms( $post_id, 'es', 'chrnx_language' ); + + $this->go_to( get_permalink( $post_id ) ); + + $this->assertSame( 'lang="es-MX" dir="ltr"', chrnx_filter_language_attributes( 'lang="en-US" dir="ltr"' ) ); + } + + /** + * Ensure a post without a language term is left untouched. + */ + public function test_language_attributes_ignore_a_post_without_a_language() { + $post_id = self::factory()->post->create(); + + $this->go_to( get_permalink( $post_id ) ); + + $this->assertSame( 'lang="en-US"', chrnx_filter_language_attributes( 'lang="en-US"' ) ); + } + + /** + * Ensure a language archive declares the language it lists. + */ + public function test_language_attributes_follow_a_language_archive() { + $post_id = self::factory()->post->create(); + wp_set_object_terms( $post_id, 'es', 'chrnx_language' ); + + $this->go_to( get_term_link( 'es', 'chrnx_language' ) ); + + $this->assertTrue( is_tax( 'chrnx_language' ) ); + $this->assertSame( 'lang="es-MX"', chrnx_filter_language_attributes( 'lang="en-US"' ) ); + } + + /** + * Ensure the home page keeps the site language. + */ + public function test_language_attributes_leave_the_home_page_alone() { + $this->go_to( home_url( '/' ) ); + + $this->assertSame( 'lang="en-US"', chrnx_filter_language_attributes( 'lang="en-US"' ) ); + } + + /** + * Ensure the head never advertises a comments feed the theme cannot render. + */ + public function test_comments_feed_is_not_advertised() { + $this->assertFalse( apply_filters( 'feed_links_show_comments_feed', true ) ); + } + /** * Ensure the local base stylesheet is enqueued with the theme version. */ diff --git a/tests/smoke/project-config.test.mjs b/tests/smoke/project-config.test.mjs index ae6235e..59e1661 100644 --- a/tests/smoke/project-config.test.mjs +++ b/tests/smoke/project-config.test.mjs @@ -12,7 +12,7 @@ test('tooling is pinned and wp-env maps this repo as chrnx', async () => { assert.equal(pkg.devDependencies['@wordpress/scripts'], '34.0.0'); assert.equal(pkg.devDependencies['@playwright/test'], '1.62.1'); assert.equal(pkg.devDependencies.lighthouse, '13.4.1'); - assert.equal(env.core, 'https://wordpress.org/wordpress-6.9.6.zip'); + assert.equal(env.core, 'https://wordpress.org/wordpress-7.0.4.zip'); assert.equal(env.phpVersion, '8.3'); assert.equal(env.autoPort, false); assert.equal(env.port, 8888);