Changeset 3830701
- Timestamp:
- 11/28/2026 01:28:33 AM (less than one hour ago)
- Location:
- vabelon
- Files:
-
- 40 edited
- 1 copied
-
tags/26.11.27.19 (copied) (copied from vabelon/trunk )
-
tags/26.11.27.19/languages/vabelon.pot (modified) (1 diff)
-
tags/26.11.27.19/readme.txt (modified) (2 diffs)
-
tags/26.11.27.19/src/Admin/Settings.php (modified) (10 diffs)
-
tags/26.11.27.19/src/Admin/TranslationsBox.php (modified) (6 diffs)
-
tags/26.11.27.19/src/Content/Translations.php (modified) (12 diffs)
-
tags/26.11.27.19/src/Frontend/ContentLinks.php (modified) (4 diffs)
-
tags/26.11.27.19/src/Frontend/Hreflang.php (modified) (7 diffs)
-
tags/26.11.27.19/src/Frontend/Locale.php (modified) (2 diffs)
-
tags/26.11.27.19/src/Frontend/Menus.php (modified) (6 diffs)
-
tags/26.11.27.19/src/Frontend/Switcher.php (modified) (6 diffs)
-
tags/26.11.27.19/src/Language/Language.php (modified) (1 diff)
-
tags/26.11.27.19/src/Language/Languages.php (modified) (10 diffs)
-
tags/26.11.27.19/src/Plugin.php (modified) (7 diffs)
-
tags/26.11.27.19/src/Routing/Permalinks.php (modified) (4 diffs)
-
tags/26.11.27.19/src/Routing/QueryLanguage.php (modified) (5 diffs)
-
tags/26.11.27.19/src/Routing/Request.php (modified) (4 diffs)
-
tags/26.11.27.19/src/Routing/Rewrites.php (modified) (8 diffs)
-
tags/26.11.27.19/src/Routing/StaticPages.php (modified) (5 diffs)
-
tags/26.11.27.19/src/Routing/Urls.php (modified) (7 diffs)
-
tags/26.11.27.19/vabelon.php (modified) (5 diffs)
-
trunk/languages/vabelon.pot (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/src/Admin/Settings.php (modified) (10 diffs)
-
trunk/src/Admin/TranslationsBox.php (modified) (6 diffs)
-
trunk/src/Content/Translations.php (modified) (12 diffs)
-
trunk/src/Frontend/ContentLinks.php (modified) (4 diffs)
-
trunk/src/Frontend/Hreflang.php (modified) (7 diffs)
-
trunk/src/Frontend/Locale.php (modified) (2 diffs)
-
trunk/src/Frontend/Menus.php (modified) (6 diffs)
-
trunk/src/Frontend/Switcher.php (modified) (6 diffs)
-
trunk/src/Language/Language.php (modified) (1 diff)
-
trunk/src/Language/Languages.php (modified) (10 diffs)
-
trunk/src/Plugin.php (modified) (7 diffs)
-
trunk/src/Routing/Permalinks.php (modified) (4 diffs)
-
trunk/src/Routing/QueryLanguage.php (modified) (5 diffs)
-
trunk/src/Routing/Request.php (modified) (4 diffs)
-
trunk/src/Routing/Rewrites.php (modified) (8 diffs)
-
trunk/src/Routing/StaticPages.php (modified) (5 diffs)
-
trunk/src/Routing/Urls.php (modified) (7 diffs)
-
trunk/vabelon.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vabelon/tags/26.11.27.19/languages/vabelon.pot
r3827447 r3830701 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Vabelon: Lightweight Multilingual, Hreflang Tags & Language Switcher 26.11.2 6.10\n"5 "Project-Id-Version: Vabelon: Lightweight Multilingual, Hreflang Tags & Language Switcher 26.11.27.19\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/vabelon\n" 7 7 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" -
vabelon/tags/26.11.27.19/readme.txt
r3827588 r3830701 5 5 Tested up to: 7.1 6 6 Requires PHP: 7.4 7 Stable tag: 26.11.2 6.107 Stable tag: 26.11.27.19 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 110 110 [View the complete release history](https://vabelon.com/changelog). 111 111 112 = 26.11.27.19 = 113 114 * Fixed: the language fields on the settings page fit their table. [Release notes](https://vabelon.com/changelog). 115 112 116 = 26.11.26.10 = 113 117 -
vabelon/tags/26.11.27.19/src/Admin/Settings.php
r3827447 r3830701 16 16 defined( 'ABSPATH' ) || exit; 17 17 18 /** 19 * Settings page, built on the WordPress Settings API. 20 */ 18 21 19 final class Settings { 22 20 … … 24 22 public const GROUP = 'vabelon'; 25 23 26 /** 27 * Hook the page into WordPress. 28 * 29 * @return void 30 */ 24 /** @return void */ 31 25 public function register(): void { 32 26 add_action( 'admin_menu', array( $this, 'menu' ) ); … … 36 30 37 31 /** 38 * Show the short name on the Plugins screen; the header and the readme keep the full name.39 *40 * While the plugin is inactive, the one-entry catalogs in languages/ do the same.41 *42 32 * @param mixed $plugins Plugins keyed by basename. 43 33 * @return mixed … … 51 41 } 52 42 53 /** 54 * Add the page under Settings. 55 * 56 * @return void 57 */ 43 /** @return void */ 58 44 public function menu(): void { 59 45 add_options_page( 'Vabelon', 'Vabelon', 'manage_options', self::PAGE, array( $this, 'render' ) ); 60 46 } 61 47 62 /** 63 * Register the option with the Settings API. 64 * 65 * @return void 66 */ 48 /** @return void */ 67 49 public function setting(): void { 68 50 register_setting( … … 87 69 88 70 /** 89 * Keep only menu choices for a configured language, a theme location and a menu that exists.90 *91 71 * @param mixed $input Submitted choices: language => location => menu ID. 92 72 * @return array<string,array<string,int>> … … 112 92 } 113 93 114 /** 115 * Print the menu choices: one row per theme location, one column per language. 116 * 117 * Shown only where it can do something: a theme with menu locations, a menu, and two languages. 118 * 119 * @return void 120 */ 94 /** @return void */ 121 95 private function menus_table(): void { 122 96 $locations = get_registered_nav_menus(); … … 149 123 150 124 /** 151 * Validate and sanitize the value before it is stored.152 *153 * Accepts the settings form (rows and default) or the stored shape (items), which154 * Languages::save() passes through update_option(). Both are validated the same way.155 *156 125 * @param mixed $input Submitted form or stored shape. 157 126 * @return mixed The value to store. … … 175 144 176 145 /** 177 * Language rows from the settings form: removed and empty rows are dropped, and178 * the chosen radio button marks the default.179 *180 146 * @param array $input Submitted form. 181 147 * @return array<int,array> … … 198 164 } 199 165 200 /** 201 * Print the page. 202 * 203 * @return void 204 */ 166 /** @return void */ 205 167 public function render(): void { 206 168 if ( ! current_user_can( 'manage_options' ) ) { … … 232 194 echo '<tr><td><input type="radio" class="vabelon-settings__field" name="' . esc_attr( Languages::OPTION ) . '[default]" value="' . esc_attr( (string) $index ) . '"' . checked( (bool) $row['is_default'], true, false ) . ' /></td>'; 233 195 foreach ( array_keys( $columns ) as $key ) { 234 echo '<td><input type="text" class=" vabelon-settings__field" name="' . esc_attr( $name . '[' . $key . ']' ) . '" value="' . esc_attr( Languages::text( $row[ $key ] ) ) . '" /></td>';196 echo '<td><input type="text" class="widefat vabelon-settings__field" name="' . esc_attr( $name . '[' . $key . ']' ) . '" value="' . esc_attr( Languages::text( $row[ $key ] ) ) . '" /></td>'; 235 197 } 236 198 echo '<td>'; -
vabelon/tags/26.11.27.19/src/Admin/TranslationsBox.php
r3826639 r3830701 16 16 defined( 'ABSPATH' ) || exit; 17 17 18 /** 19 * Editor meta box. 20 */ 18 21 19 final class TranslationsBox { 22 20 23 /** 24 * Hook the box into WordPress. 25 * 26 * @return void 27 */ 21 /** @return void */ 28 22 public function register(): void { 29 23 add_action( 'add_meta_boxes', array( $this, 'add' ) ); … … 32 26 } 33 27 34 /** 35 * Add the box to every supported post type. 36 * 37 * @return void 38 */ 28 /** @return void */ 39 29 public function add(): void { 40 30 foreach ( Plugin::translations()->post_types() as $type ) { … … 44 34 45 35 /** 46 * Print the box.47 *48 36 * @param WP_Post $post Post being edited. 49 37 * @return void … … 75 63 76 64 /** 77 * Save the box.78 *79 65 * @param int $post_id Post ID. 80 66 * @param WP_Post $post Post being saved. … … 103 89 104 90 /** 105 * Apply the box's choices to a post.106 *107 91 * @param int $post_id Post ID. 108 92 * @param string $language Chosen language. … … 137 121 } 138 122 139 /** 140 * Show the last error once. 141 * 142 * @return void 143 */ 123 /** @return void */ 144 124 public function notice(): void { 145 125 $key = 'vabelon_box_error_' . get_current_user_id(); -
vabelon/tags/26.11.27.19/src/Content/Translations.php
r3826639 r3830701 18 18 defined( 'ABSPATH' ) || exit; 19 19 20 /** 21 * Reads and writes the two taxonomies. 22 */ 20 23 21 final class Translations { 24 22 … … 26 24 public const GROUP = 'vabelon_group'; 27 25 28 /** 29 * Hook the taxonomies into WordPress. 30 * 31 * @return void 32 */ 26 /** @return void */ 33 27 public function register(): void { 34 28 add_action( 'init', array( $this, 'register_taxonomies' ), 5 ); 35 29 } 36 30 37 /** 38 * Register both hidden taxonomies. 39 * 40 * @return void 41 */ 31 /** @return void */ 42 32 public function register_taxonomies(): void { 43 33 foreach ( array( self::LANGUAGE, self::GROUP ) as $taxonomy ) { … … 54 44 } 55 45 56 /** 57 * Post types that can have a language. 58 * 59 * @return array<int,string> 60 */ 46 /** @return array<int,string> */ 61 47 public function post_types(): array { 62 48 $types = apply_filters( 'vabelon_post_types', array( 'post', 'page' ) ); … … 66 52 67 53 /** 68 * Whether a post can have a language.69 *70 54 * @param int $post_id Post ID. 71 55 * @return bool … … 77 61 78 62 /** 79 * The language a post was given, or null.80 *81 63 * @param int $post_id Post ID. 82 64 * @return string|null … … 88 70 89 71 /** 90 * The language a post is shown in: its own, or the default.91 *92 72 * @param int $post_id Post ID. 93 73 * @return string … … 99 79 100 80 /** 101 * Give a post a language.102 *103 81 * @param int $post_id Post ID. 104 82 * @param string $slug Language address prefix. … … 114 92 115 93 /** 116 * The translation group of a post, or null.117 *118 94 * @param int $post_id Post ID. 119 95 * @return string|null … … 124 100 125 101 /** 126 * A post and its translations, as language => post ID.127 *128 102 * @param int $post_id Post ID. 129 103 * @param array<int,string> $statuses Keep only posts with one of these statuses; empty keeps all. … … 152 126 153 127 /** 154 * Link a post as the translation of another, in a language.155 *156 128 * @param int $source Post that already exists in its language. 157 129 * @param int $target Post that becomes the translation. … … 195 167 196 168 /** 197 * Take a post out of its translation group.198 *199 169 * @param int $post_id Post ID. 200 170 * @return bool Whether the post was in a group. … … 221 191 222 192 /** 223 * Slug of the first term a post has in a taxonomy, or null.224 *225 193 * @param int $post_id Post ID. 226 194 * @param string $taxonomy Taxonomy name. -
vabelon/tags/26.11.27.19/src/Frontend/ContentLinks.php
r3827447 r3830701 14 14 defined( 'ABSPATH' ) || exit; 15 15 16 /** 17 * Links in post content. 18 * 19 * The stored content is never changed. A link is pointed at its translation when the page is shown, 20 * so it starts following a translation the day that translation is published. 21 */ 16 22 17 final class ContentLinks { 23 18 24 /** 25 * Translated address per language and path; null when there is none. 26 * 27 * @var array<string,string|null> 28 */ 19 /** @var array<string,string|null> */ 29 20 private array $seen = array(); 30 21 31 /** 32 * Hook into WordPress. 33 * 34 * @return void 35 */ 22 /** @return void */ 36 23 public function register(): void { 37 24 add_filter( 'the_content', array( $this, 'localize' ), 20 ); … … 39 26 40 27 /** 41 * Point the links of a translated page at translations.42 *43 28 * @param mixed $content Post content. 44 29 * @return mixed … … 64 49 65 50 /** 66 * The address a link should have in a language, or null to leave it alone.67 *68 * Only links to this site are considered, and only when the linked post has a published69 * translation. A link to a page nobody translated keeps working in the other language.70 *71 51 * @param string $href Address as written. 72 52 * @param string $language Language address prefix. … … 82 62 $key = $language . ' ' . $path; 83 63 if ( ! array_key_exists( $key, $this->seen ) ) { 84 // The lookup must see every language, so it runs as a request that is not a visitor's. 64 85 65 add_filter( 'vabelon_request_is_public', '__return_false', 99 ); 86 66 $post_id = url_to_postid( $path ); -
vabelon/tags/26.11.27.19/src/Frontend/Hreflang.php
r3827447 r3830701 15 15 defined( 'ABSPATH' ) || exit; 16 16 17 /** 18 * Hreflang links. 19 */ 17 20 18 final class Hreflang { 21 19 22 /** 23 * Hook into WordPress. 24 * 25 * @return void 26 */ 20 /** @return void */ 27 21 public function register(): void { 28 22 add_action( 'wp_head', array( $this, 'output' ), 2 ); … … 30 24 31 25 /** 32 * Alternates of a post: one row per published translation, plus x-default.33 *34 26 * @param int $post_id Post ID. 35 27 * @return array<int,array{hreflang:string,href:string}> … … 44 36 } 45 37 46 /** 47 * Alternates of the home page. 48 * 49 * @return array<int,array{hreflang:string,href:string}> 50 */ 38 /** @return array<int,array{hreflang:string,href:string}> */ 51 39 public function home_model(): array { 52 40 if ( 'page' === get_option( 'show_on_front' ) ) { … … 62 50 63 51 /** 64 * The link elements for a list of alternates.65 *66 52 * @param array<int,array{hreflang:string,href:string}> $model Alternates. 67 53 * @return string … … 75 61 } 76 62 77 /** 78 * Print the alternates of the current page. 79 * 80 * @return void 81 */ 63 /** @return void */ 82 64 public function output(): void { 83 65 if ( is_404() || is_preview() || is_search() || is_archive() || is_paged() ) { … … 86 68 $model = array(); 87 69 if ( is_singular() || ( is_home() && ! is_front_page() ) ) { 88 // A posts page is a page too: its translations are the other languages' blog indexes. 70 89 71 $model = $this->singular_model( get_queried_object_id() ); 90 72 } elseif ( is_front_page() ) { … … 95 77 96 78 /** 97 * Rows in language order, with x-default pointing at the default language.98 *99 79 * @param array<string,string> $addresses Language address prefix => address. 100 80 * @return array<int,array{hreflang:string,href:string}> -
vabelon/tags/26.11.27.19/src/Frontend/Locale.php
r3826639 r3830701 14 14 defined( 'ABSPATH' ) || exit; 15 15 16 /** 17 * Locale per language. 18 */ 16 19 17 final class Locale { 20 18 21 /** 22 * Whether the locale is being resolved right now. 23 * 24 * @var bool 25 */ 19 /** @var bool */ 26 20 private bool $resolving = false; 27 21 28 /** 29 * Hook into WordPress. 30 * 31 * @return void 32 */ 22 /** @return void */ 33 23 public function register(): void { 34 24 add_filter( 'determine_locale', array( $this, 'filter' ), 20 ); … … 37 27 38 28 /** 39 * The locale of the request's language.40 *41 29 * @param mixed $locale Locale WordPress chose. 42 30 * @return mixed -
vabelon/tags/26.11.27.19/src/Frontend/Menus.php
r3827447 r3830701 14 14 defined( 'ABSPATH' ) || exit; 15 15 16 /** 17 * Navigation menus. 18 */ 16 19 17 final class Menus { 20 18 21 19 public const OPTION = 'vabelon_menu_locations'; 22 20 23 /** 24 * Hook into WordPress. 25 * 26 * @return void 27 */ 21 /** @return void */ 28 22 public function register(): void { 29 23 add_filter( 'theme_mod_nav_menu_locations', array( $this, 'filter_locations' ) ); … … 31 25 } 32 26 33 /** 34 * The stored choices: language address prefix => theme location => menu ID. 35 * 36 * @return array<string,array<string,int>> 37 */ 27 /** @return array<string,array<string,int>> */ 38 28 public static function map(): array { 39 29 $stored = get_option( self::OPTION, array() ); … … 50 40 51 41 /** 52 * Menu locations for the language of the request.53 *54 42 * @param mixed $locations Theme location => menu ID. 55 43 * @return mixed … … 60 48 61 49 /** 62 * Menu locations for a language.63 *64 * A language with no menus of its own uses the default language's. Once a language has65 * a menu, a location it leaves empty shows no menu on its pages.66 *67 50 * @param array<mixed> $locations Theme location => menu ID. 68 51 * @param string $language Language address prefix. … … 90 73 91 74 /** 92 * Menu items for the language of the request.93 *94 75 * @param mixed $items Menu items. 95 76 * @return mixed … … 100 81 101 82 /** 102 * Point each item that links a post at the post's published translation.103 *104 * An item whose post has no translation keeps its address.105 *106 83 * @param array<int|string,mixed> $items Menu items. 107 84 * @param string $language Language address prefix. -
vabelon/tags/26.11.27.19/src/Frontend/Switcher.php
r3827447 r3830701 15 15 defined( 'ABSPATH' ) || exit; 16 16 17 /** 18 * Language switcher. 19 */ 17 20 18 final class Switcher { 21 19 … … 36 34 ); 37 35 38 /** 39 * Hook into WordPress. 40 * 41 * @return void 42 */ 36 /** @return void */ 43 37 public function register(): void { 44 38 add_shortcode( 'vabelon_switcher', array( $this, 'shortcode' ) ); … … 47 41 48 42 /** 49 * The links to show.50 *51 43 * @param int|null $post_id Post being viewed, or null on a page that is not one post. 52 44 * @param string $active Language of the page being viewed. … … 73 65 74 66 /** 75 * The switcher's markup; empty when there is nothing to switch to.76 *77 67 * @param array<int,array{slug:string,label:string,hreflang:string,url:string,is_current:bool}> $items Links. 78 68 * @return string … … 96 86 } 97 87 98 /** 99 * The switcher for the page being viewed. 100 * 101 * @return string 102 */ 88 /** @return string */ 103 89 public function shortcode(): string { 104 90 $post_id = is_singular() || ( is_home() && ! is_front_page() ) ? get_queried_object_id() : 0; … … 108 94 } 109 95 110 /** 111 * Print the switcher for the page being viewed. 112 * 113 * @return void 114 */ 96 /** @return void */ 115 97 public function output(): void { 116 98 echo wp_kses( $this->shortcode(), self::ALLOWED ); -
vabelon/tags/26.11.27.19/src/Language/Language.php
r3826639 r3830701 12 12 defined( 'ABSPATH' ) || exit; 13 13 14 /** 15 * Description of a language. Built by Languages from validated rows. 16 */ 14 17 15 final class Language { 18 16 19 /** 20 * Address prefix, such as "es". 21 * 22 * @var string 23 */ 17 /** @var string */ 24 18 public string $slug; 25 19 26 /** 27 * WordPress locale, such as "es_ES". 28 * 29 * @var string 30 */ 20 /** @var string */ 31 21 public string $wp_locale; 32 22 33 /** 34 * Value for hreflang attributes, such as "es". 35 * 36 * @var string 37 */ 23 /** @var string */ 38 24 public string $hreflang; 39 25 40 /** 41 * Name in the site's language. 42 * 43 * @var string 44 */ 26 /** @var string */ 45 27 public string $name; 46 28 47 /** 48 * Name in the language itself. 49 * 50 * @var string 51 */ 29 /** @var string */ 52 30 public string $native_name; 53 31 54 /** 55 * Whether this is the site's default language. 56 * 57 * @var bool 58 */ 32 /** @var bool */ 59 33 public bool $is_default; 60 34 61 /** 62 * Constructor. 63 * 64 * @param array{slug:string,wp_locale:string,hreflang:string,name:string,native_name:string,is_default:bool} $row Validated row. 65 */ 35 /** @param array{slug:string,wp_locale:string,hreflang:string,name:string,native_name:string,is_default:bool} $row Validated row. */ 66 36 public function __construct( array $row ) { 67 37 $this->slug = $row['slug']; -
vabelon/tags/26.11.27.19/src/Language/Languages.php
r3826639 r3830701 14 14 defined( 'ABSPATH' ) || exit; 15 15 16 /** 17 * Language registry. 18 */ 16 19 17 final class Languages { 20 18 … … 23 21 private const RESERVED = array( 'wp-admin', 'wp-json', 'wp-content', 'wp-includes', 'feed', 'page', 'author', 'category', 'tag', 'search', 'comments', 'embed' ); 24 22 25 /** 26 * Languages read during this request. 27 * 28 * @var array<int,Language>|null 29 */ 23 /** @var array<int,Language>|null */ 30 24 private ?array $cache = null; 31 25 32 /** 33 * Fingerprint of the stored option the cache was built from. 34 * 35 * @var string 36 */ 26 /** @var string */ 37 27 private string $cache_key = ''; 38 28 39 /** 40 * Every configured language, in stored order. 41 * 42 * @return array<int,Language> 43 */ 29 /** @return array<int,Language> */ 44 30 public function all(): array { 45 31 $stored = get_option( self::OPTION, array() ); … … 60 46 61 47 /** 62 * One language by its address prefix.63 *64 48 * @param string $slug Address prefix. 65 49 * @return Language|null … … 74 58 } 75 59 76 /** 77 * Address prefix of the default language, or '' when none is configured. 78 * 79 * @return string 80 */ 60 /** @return string */ 81 61 public function default_slug(): string { 82 62 foreach ( $this->all() as $language ) { … … 88 68 } 89 69 90 /** 91 * Address prefixes of every language except the default. 92 * 93 * @return array<int,string> 94 */ 70 /** @return array<int,string> */ 95 71 public function non_default_slugs(): array { 96 72 $slugs = array(); … … 104 80 105 81 /** 106 * Check and normalize a list of language rows. Writes nothing.107 *108 82 * @param array $rows Rows with slug, wp_locale, hreflang, name, native_name and is_default. 109 83 * @return array<int,array{slug:string,wp_locale:string,hreflang:string,name:string,native_name:string,is_default:bool}>|WP_Error … … 145 119 146 120 /** 147 * Save a list of language rows.148 *149 121 * @param array $rows Rows as accepted by validate(). 150 122 * @return true|WP_Error … … 167 139 } 168 140 169 /** 170 * On first activation, make the site's own language the default. 171 * 172 * @return void 173 */ 141 /** @return void */ 174 142 public function seed_from_site_locale(): void { 175 143 if ( false !== get_option( self::OPTION, false ) ) { … … 193 161 194 162 /** 195 * Name of the first field of a row that is not valid, or ''.196 *197 163 * @param array{slug:string,wp_locale:string,hreflang:string,name:string,native_name:string,is_default:bool} $item Row. 198 164 * @return string … … 217 183 218 184 /** 219 * A string from a scalar value; '' for anything else.220 *221 185 * @param mixed $value Value. 222 186 * @return string -
vabelon/tags/26.11.27.19/src/Plugin.php
r3827447 r3830701 17 17 defined( 'ABSPATH' ) || exit; 18 18 19 /** 20 * Plugin bootstrap and the four objects every component shares. 21 */ 19 22 20 final class Plugin { 23 21 24 /** 25 * Shared objects, created on first use. 26 * 27 * @var array<string,object> 28 */ 22 /** @var array<string,object> */ 29 23 private static array $shared = array(); 30 24 31 /** 32 * Register every component once. 33 * 34 * @return void 35 */ 25 /** @return void */ 36 26 public static function boot(): void { 37 27 if ( isset( self::$shared['booted'] ) ) { … … 57 47 } 58 48 59 /** 60 * The language registry. 61 * 62 * @return Languages 63 */ 49 /** @return Languages */ 64 50 public static function languages(): Languages { 65 51 $found = self::$shared['languages'] ?? null; … … 71 57 } 72 58 73 /** 74 * The translation storage. 75 * 76 * @return Translations 77 */ 59 /** @return Translations */ 78 60 public static function translations(): Translations { 79 61 $found = self::$shared['translations'] ?? null; … … 85 67 } 86 68 87 /** 88 * The language addresses. 89 * 90 * @return Urls 91 */ 69 /** @return Urls */ 92 70 public static function urls(): Urls { 93 71 $found = self::$shared['urls'] ?? null; … … 99 77 } 100 78 101 /** 102 * The request language. 103 * 104 * @return Request 105 */ 79 /** @return Request */ 106 80 public static function request(): Request { 107 81 $found = self::$shared['request'] ?? null; … … 113 87 } 114 88 115 /** 116 * Activation: make the site's language the default and rebuild the routes on the next request. 117 * 118 * @return void 119 */ 89 /** @return void */ 120 90 public static function activate(): void { 121 91 self::languages()->seed_from_site_locale(); … … 123 93 } 124 94 125 /** 126 * Deactivation: let WordPress rebuild its rules without the language routes. 127 * 128 * @return void 129 */ 95 /** @return void */ 130 96 public static function deactivate(): void { 131 97 delete_option( 'vabelon_rewrite_signature' ); -
vabelon/tags/26.11.27.19/src/Routing/Permalinks.php
r3826639 r3830701 15 15 defined( 'ABSPATH' ) || exit; 16 16 17 /** 18 * Permalink filters. 19 */ 17 20 18 final class Permalinks { 21 19 22 20 private const ARCHIVE_FILTERS = array( 'post_type_archive_link', 'search_link', 'feed_link', 'year_link', 'month_link', 'day_link', 'author_link', 'get_pagenum_link', 'term_link' ); 23 21 24 /** 25 * Whether home_url() is being filtered right now. 26 * 27 * @var bool 28 */ 22 /** @var bool */ 29 23 private bool $filtering_home = false; 30 24 31 /** 32 * Hook the filters into WordPress. 33 * 34 * @return void 35 */ 25 /** @return void */ 36 26 public function register(): void { 37 27 foreach ( array( 'post_link', 'page_link', 'post_type_link' ) as $filter ) { … … 45 35 46 36 /** 47 * Address of a post, in the post's own language.48 *49 37 * @param mixed $url Address WordPress built. 50 38 * @param mixed $post Post object or ID. … … 61 49 62 50 /** 63 * Address of an archive, search or feed, in the language of the request.64 *65 51 * @param mixed $url Address WordPress built. 66 52 * @return mixed … … 74 60 75 61 /** 76 * The home address, in the language of the request.77 *78 62 * @param mixed $url Address WordPress built. 79 63 * @param mixed $path Path that was asked for. -
vabelon/tags/26.11.27.19/src/Routing/QueryLanguage.php
r3827447 r3830701 18 18 defined( 'ABSPATH' ) || exit; 19 19 20 /** 21 * Query scoping. 22 */ 20 23 21 final class QueryLanguage { 24 22 25 /** 26 * Hook the scoping into WordPress. 27 * 28 * @return void 29 */ 23 /** @return void */ 30 24 public function register(): void { 31 25 add_action( 'pre_get_posts', array( $this, 'scope' ), 1 ); … … 35 29 36 30 /** 37 * Limit a list query to one language.38 *39 * A request for one specific post is left alone: StaticPages sends it to its own address.40 *41 31 * @param WP_Query $query Query about to run. 42 32 * @return void … … 47 37 return; 48 38 } 49 // WordPress leaves the post type empty on the blog index, search, feeds and most archives. 39 50 40 $types = array_filter( 51 41 (array) $query->get( 'post_type' ), … … 76 66 77 67 /** 78 * Keep the previous and next post links inside the language of the post being viewed.79 *80 68 * @param mixed $where WHERE clause of the adjacent post query; the posts table is aliased p. 81 69 * @param mixed $same Unused. … … 103 91 return $default ? $where : $where . ' AND 1 = 0'; 104 92 } 105 // $ids holds integers only, read from the language terms above. 93 106 94 return $where . ' AND p.ID ' . ( $default ? 'NOT IN' : 'IN' ) . " ( SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN ( " . implode( ',', $ids ) . ' ) )'; 107 95 } -
vabelon/tags/26.11.27.19/src/Routing/Request.php
r3826639 r3830701 14 14 defined( 'ABSPATH' ) || exit; 15 15 16 /** 17 * Request language. 18 */ 16 19 17 final class Request { 20 18 21 /** 22 * Language resolved for this request. 23 * 24 * @var string|null 25 */ 19 /** @var string|null */ 26 20 private ?string $resolved = null; 27 21 28 /** 29 * Address prefix of the language this request is for. 30 * 31 * @return string 32 */ 22 /** @return string */ 33 23 public function language(): string { 34 24 if ( ! $this->is_public() ) { … … 43 33 44 34 /** 45 * The language an address belongs to.46 *47 35 * @param string $uri Request address, path first. 48 36 * @return string … … 52 40 } 53 41 54 /** 55 * Whether this is a visitor-facing page request. 56 * 57 * @return bool 58 */ 42 /** @return bool */ 59 43 public function is_public(): bool { 60 44 global $pagenow; … … 69 53 } 70 54 71 /** 72 * The site's home address as stored, without a trailing slash. 73 * 74 * @return string 75 */ 55 /** @return string */ 76 56 public static function home(): string { 77 57 $home = get_option( 'home', '' ); -
vabelon/tags/26.11.27.19/src/Routing/Rewrites.php
r3827447 r3830701 14 14 defined( 'ABSPATH' ) || exit; 15 15 16 /** 17 * Rewrite rules. 18 */ 16 19 17 final class Rewrites { 20 18 21 19 private const FAMILIES = array( 'post', 'page', 'date', 'author', 'search', 'root', 'category', 'post_tag' ); 22 20 23 /** 24 * Hook the rules into WordPress. 25 * 26 * @return void 27 */ 21 /** @return void */ 28 22 public function register(): void { 29 23 add_filter( 'query_vars', array( $this, 'query_vars' ) ); … … 38 32 39 33 /** 40 * Allow the language in the query.41 *42 34 * @param array<int,string> $vars Public query variables. 43 35 * @return array<int,string> … … 49 41 50 42 /** 51 * Add a copy of each rule that starts with a language prefix.52 *53 43 * @param array<string,string> $rules Rules of one family. 54 44 * @return array<string,string> … … 79 69 } 80 70 81 /** 82 * Add the rule for each language's home address. 83 * 84 * @return void 85 */ 71 /** @return void */ 86 72 public function add_home_rule(): void { 87 73 $group = $this->language_group(); … … 91 77 } 92 78 93 /** 94 * Rebuild WordPress's rules when the languages or the address structure changed. 95 * 96 * @return void 97 */ 79 /** @return void */ 98 80 public function maybe_flush(): void { 99 81 $signature = hash( 'sha256', (string) wp_json_encode( array( VABELON_VERSION, Plugin::languages()->all(), get_option( 'permalink_structure', '' ) ) ) ); … … 106 88 107 89 /** 108 * Stop WordPress redirecting a language address to another language.109 *110 90 * @param mixed $redirect Address WordPress wants to redirect to. 111 91 * @param mixed $requested Address that was requested. … … 123 103 } 124 104 125 /** 126 * Give a language home one address: with or without the trailing slash, as the permalink structure says. 127 * 128 * @return void 129 */ 105 /** @return void */ 130 106 public function home_slash(): void { 131 107 $method = isset( $_SERVER['REQUEST_METHOD'] ) && is_string( $_SERVER['REQUEST_METHOD'] ) ? sanitize_key( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) : ''; … … 147 123 } 148 124 149 /** 150 * Regex group matching every language prefix except the default, followed by a slash. 151 * 152 * @return string 153 */ 125 /** @return string */ 154 126 private function language_group(): string { 155 127 $slugs = Plugin::languages()->non_default_slugs(); -
vabelon/tags/26.11.27.19/src/Routing/StaticPages.php
r3827447 r3830701 15 15 defined( 'ABSPATH' ) || exit; 16 16 17 /** 18 * Static front page and posts page per language. 19 */ 17 20 18 final class StaticPages { 21 19 22 /** 23 * Whether the front page option is being read unfiltered. 24 * 25 * @var bool 26 */ 20 /** @var bool */ 27 21 private static bool $reading_original = false; 28 22 29 /** 30 * Hook into WordPress. 31 * 32 * @return void 33 */ 23 /** @return void */ 34 24 public function register(): void { 35 25 add_filter( 'option_page_on_front', array( $this, 'front_page_id' ) ); … … 39 29 } 40 30 41 /** 42 * The front page chosen in Settings > Reading, in the default language. 43 * 44 * @return int 45 */ 31 /** @return int */ 46 32 public static function original_front(): int { 47 33 self::$reading_original = true; … … 52 38 53 39 /** 54 * On a language address, the front page and the posts page are their translations in that language.55 *56 * WordPress then treats a request for the translated posts page as that language's blog index.57 *58 40 * @param mixed $value Stored page ID. 59 41 * @return mixed … … 72 54 73 55 /** 74 * Turn a language home request into a request for that language's front page.75 *76 56 * @param WP_Query $query Query about to run. 77 57 * @return void … … 101 81 } 102 82 103 /** 104 * Send a request for a post in another language to the post's own address. 105 * 106 * @return void 107 */ 83 /** @return void */ 108 84 public function redirect_to_language(): void { 109 85 if ( ! is_singular() || is_preview() ) { -
vabelon/tags/26.11.27.19/src/Routing/Urls.php
r3827447 r3830701 14 14 defined( 'ABSPATH' ) || exit; 15 15 16 /** 17 * Language addresses. 18 */ 16 19 17 final class Urls { 20 18 21 19 /** 22 * Home address of a language.23 *24 20 * @param string $slug Language address prefix. 25 21 * @return string … … 30 26 31 27 /** 32 * Whether a post is the front page or one of its translations.33 *34 28 * @param int $post_id Post ID. 35 29 * @return bool … … 44 38 45 39 /** 46 * Put an address into a language.47 *48 40 * @param string $url Address on this site. 49 41 * @param string $slug Language address prefix. … … 76 68 77 69 /** 78 * The language an address belongs to.79 *80 70 * @param string $url Address. 81 71 * @return string … … 89 79 90 80 /** 91 * End a path the way the site's permalink structure does.92 *93 * Addresses are also built before WordPress sets up its rewrite object, where94 * user_trailingslashit() cannot be called.95 *96 81 * @param string $path Path without a trailing slash. 97 82 * @return string … … 106 91 107 92 /** 108 * A path relative to the home path, with any language prefix removed.109 *110 93 * @param string $path Path of an address. 111 94 * @param string $base Path of the home address. … … 130 113 131 114 /** 132 * Whether a parsed address is on this site.133 *134 115 * @param array<string,int|string> $parts Parsed address. 135 116 * @return bool -
vabelon/tags/26.11.27.19/vabelon.php
r3827447 r3830701 3 3 * Plugin Name: Vabelon: Lightweight Multilingual, Hreflang Tags & Language Switcher 4 4 * Description: Multilingual WordPress in a small plugin: languages, translated addresses, hreflang and a language switcher. 5 * Version: 26.11.2 6.105 * Version: 26.11.27.19 6 6 * Requires at least: 6.2 7 7 * Requires PHP: 7.4 … … 20 20 defined( 'ABSPATH' ) || exit; 21 21 22 define( 'VABELON_VERSION', '26.11.2 6.10' );22 define( 'VABELON_VERSION', '26.11.27.19' ); 23 23 define( 'VABELON_FILE', __FILE__ ); 24 24 define( 'VABELON_PATH', plugin_dir_path( __FILE__ ) ); … … 40 40 add_action( 'plugins_loaded', array( \Vabelon\Plugin::class, 'boot' ) ); 41 41 42 /** 43 * Print the language switcher. For use in theme templates. 44 * 45 * @return void 46 */ 42 /** @return void */ 47 43 function vabelon_switcher(): void { 48 44 do_action( 'vabelon_switcher' ); 49 45 } 50 46 51 /** 52 * Address prefix of the language the current request is for. 53 * 54 * @return string 55 */ 47 /** @return string */ 56 48 function vabelon_current_language(): string { 57 49 return \Vabelon\Plugin::request()->language(); 58 50 } 59 51 60 /** 61 * The configured languages, default first: slug, wp_locale, hreflang, name, native_name, is_default. 62 * 63 * @return array<int,array<string,mixed>> 64 */ 52 /** @return array<int,array<string,mixed>> */ 65 53 function vabelon_languages(): array { 66 54 return array_values( array_map( 'get_object_vars', \Vabelon\Plugin::languages()->all() ) ); … … 68 56 69 57 /** 70 * The language a post was given, or null when it has none and is shown as the default language.71 *72 58 * @param int $post_id Post ID. 73 59 * @return string|null … … 78 64 79 65 /** 80 * A post and its translations, as language address prefix => post ID.81 *82 66 * @param int $post_id Post ID. 83 67 * @param array<int,string> $statuses Keep only posts with one of these statuses; empty keeps all. -
vabelon/trunk/languages/vabelon.pot
r3827447 r3830701 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Vabelon: Lightweight Multilingual, Hreflang Tags & Language Switcher 26.11.2 6.10\n"5 "Project-Id-Version: Vabelon: Lightweight Multilingual, Hreflang Tags & Language Switcher 26.11.27.19\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/vabelon\n" 7 7 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" -
vabelon/trunk/readme.txt
r3827588 r3830701 5 5 Tested up to: 7.1 6 6 Requires PHP: 7.4 7 Stable tag: 26.11.2 6.107 Stable tag: 26.11.27.19 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 110 110 [View the complete release history](https://vabelon.com/changelog). 111 111 112 = 26.11.27.19 = 113 114 * Fixed: the language fields on the settings page fit their table. [Release notes](https://vabelon.com/changelog). 115 112 116 = 26.11.26.10 = 113 117 -
vabelon/trunk/src/Admin/Settings.php
r3827447 r3830701 16 16 defined( 'ABSPATH' ) || exit; 17 17 18 /** 19 * Settings page, built on the WordPress Settings API. 20 */ 18 21 19 final class Settings { 22 20 … … 24 22 public const GROUP = 'vabelon'; 25 23 26 /** 27 * Hook the page into WordPress. 28 * 29 * @return void 30 */ 24 /** @return void */ 31 25 public function register(): void { 32 26 add_action( 'admin_menu', array( $this, 'menu' ) ); … … 36 30 37 31 /** 38 * Show the short name on the Plugins screen; the header and the readme keep the full name.39 *40 * While the plugin is inactive, the one-entry catalogs in languages/ do the same.41 *42 32 * @param mixed $plugins Plugins keyed by basename. 43 33 * @return mixed … … 51 41 } 52 42 53 /** 54 * Add the page under Settings. 55 * 56 * @return void 57 */ 43 /** @return void */ 58 44 public function menu(): void { 59 45 add_options_page( 'Vabelon', 'Vabelon', 'manage_options', self::PAGE, array( $this, 'render' ) ); 60 46 } 61 47 62 /** 63 * Register the option with the Settings API. 64 * 65 * @return void 66 */ 48 /** @return void */ 67 49 public function setting(): void { 68 50 register_setting( … … 87 69 88 70 /** 89 * Keep only menu choices for a configured language, a theme location and a menu that exists.90 *91 71 * @param mixed $input Submitted choices: language => location => menu ID. 92 72 * @return array<string,array<string,int>> … … 112 92 } 113 93 114 /** 115 * Print the menu choices: one row per theme location, one column per language. 116 * 117 * Shown only where it can do something: a theme with menu locations, a menu, and two languages. 118 * 119 * @return void 120 */ 94 /** @return void */ 121 95 private function menus_table(): void { 122 96 $locations = get_registered_nav_menus(); … … 149 123 150 124 /** 151 * Validate and sanitize the value before it is stored.152 *153 * Accepts the settings form (rows and default) or the stored shape (items), which154 * Languages::save() passes through update_option(). Both are validated the same way.155 *156 125 * @param mixed $input Submitted form or stored shape. 157 126 * @return mixed The value to store. … … 175 144 176 145 /** 177 * Language rows from the settings form: removed and empty rows are dropped, and178 * the chosen radio button marks the default.179 *180 146 * @param array $input Submitted form. 181 147 * @return array<int,array> … … 198 164 } 199 165 200 /** 201 * Print the page. 202 * 203 * @return void 204 */ 166 /** @return void */ 205 167 public function render(): void { 206 168 if ( ! current_user_can( 'manage_options' ) ) { … … 232 194 echo '<tr><td><input type="radio" class="vabelon-settings__field" name="' . esc_attr( Languages::OPTION ) . '[default]" value="' . esc_attr( (string) $index ) . '"' . checked( (bool) $row['is_default'], true, false ) . ' /></td>'; 233 195 foreach ( array_keys( $columns ) as $key ) { 234 echo '<td><input type="text" class=" vabelon-settings__field" name="' . esc_attr( $name . '[' . $key . ']' ) . '" value="' . esc_attr( Languages::text( $row[ $key ] ) ) . '" /></td>';196 echo '<td><input type="text" class="widefat vabelon-settings__field" name="' . esc_attr( $name . '[' . $key . ']' ) . '" value="' . esc_attr( Languages::text( $row[ $key ] ) ) . '" /></td>'; 235 197 } 236 198 echo '<td>'; -
vabelon/trunk/src/Admin/TranslationsBox.php
r3826639 r3830701 16 16 defined( 'ABSPATH' ) || exit; 17 17 18 /** 19 * Editor meta box. 20 */ 18 21 19 final class TranslationsBox { 22 20 23 /** 24 * Hook the box into WordPress. 25 * 26 * @return void 27 */ 21 /** @return void */ 28 22 public function register(): void { 29 23 add_action( 'add_meta_boxes', array( $this, 'add' ) ); … … 32 26 } 33 27 34 /** 35 * Add the box to every supported post type. 36 * 37 * @return void 38 */ 28 /** @return void */ 39 29 public function add(): void { 40 30 foreach ( Plugin::translations()->post_types() as $type ) { … … 44 34 45 35 /** 46 * Print the box.47 *48 36 * @param WP_Post $post Post being edited. 49 37 * @return void … … 75 63 76 64 /** 77 * Save the box.78 *79 65 * @param int $post_id Post ID. 80 66 * @param WP_Post $post Post being saved. … … 103 89 104 90 /** 105 * Apply the box's choices to a post.106 *107 91 * @param int $post_id Post ID. 108 92 * @param string $language Chosen language. … … 137 121 } 138 122 139 /** 140 * Show the last error once. 141 * 142 * @return void 143 */ 123 /** @return void */ 144 124 public function notice(): void { 145 125 $key = 'vabelon_box_error_' . get_current_user_id(); -
vabelon/trunk/src/Content/Translations.php
r3826639 r3830701 18 18 defined( 'ABSPATH' ) || exit; 19 19 20 /** 21 * Reads and writes the two taxonomies. 22 */ 20 23 21 final class Translations { 24 22 … … 26 24 public const GROUP = 'vabelon_group'; 27 25 28 /** 29 * Hook the taxonomies into WordPress. 30 * 31 * @return void 32 */ 26 /** @return void */ 33 27 public function register(): void { 34 28 add_action( 'init', array( $this, 'register_taxonomies' ), 5 ); 35 29 } 36 30 37 /** 38 * Register both hidden taxonomies. 39 * 40 * @return void 41 */ 31 /** @return void */ 42 32 public function register_taxonomies(): void { 43 33 foreach ( array( self::LANGUAGE, self::GROUP ) as $taxonomy ) { … … 54 44 } 55 45 56 /** 57 * Post types that can have a language. 58 * 59 * @return array<int,string> 60 */ 46 /** @return array<int,string> */ 61 47 public function post_types(): array { 62 48 $types = apply_filters( 'vabelon_post_types', array( 'post', 'page' ) ); … … 66 52 67 53 /** 68 * Whether a post can have a language.69 *70 54 * @param int $post_id Post ID. 71 55 * @return bool … … 77 61 78 62 /** 79 * The language a post was given, or null.80 *81 63 * @param int $post_id Post ID. 82 64 * @return string|null … … 88 70 89 71 /** 90 * The language a post is shown in: its own, or the default.91 *92 72 * @param int $post_id Post ID. 93 73 * @return string … … 99 79 100 80 /** 101 * Give a post a language.102 *103 81 * @param int $post_id Post ID. 104 82 * @param string $slug Language address prefix. … … 114 92 115 93 /** 116 * The translation group of a post, or null.117 *118 94 * @param int $post_id Post ID. 119 95 * @return string|null … … 124 100 125 101 /** 126 * A post and its translations, as language => post ID.127 *128 102 * @param int $post_id Post ID. 129 103 * @param array<int,string> $statuses Keep only posts with one of these statuses; empty keeps all. … … 152 126 153 127 /** 154 * Link a post as the translation of another, in a language.155 *156 128 * @param int $source Post that already exists in its language. 157 129 * @param int $target Post that becomes the translation. … … 195 167 196 168 /** 197 * Take a post out of its translation group.198 *199 169 * @param int $post_id Post ID. 200 170 * @return bool Whether the post was in a group. … … 221 191 222 192 /** 223 * Slug of the first term a post has in a taxonomy, or null.224 *225 193 * @param int $post_id Post ID. 226 194 * @param string $taxonomy Taxonomy name. -
vabelon/trunk/src/Frontend/ContentLinks.php
r3827447 r3830701 14 14 defined( 'ABSPATH' ) || exit; 15 15 16 /** 17 * Links in post content. 18 * 19 * The stored content is never changed. A link is pointed at its translation when the page is shown, 20 * so it starts following a translation the day that translation is published. 21 */ 16 22 17 final class ContentLinks { 23 18 24 /** 25 * Translated address per language and path; null when there is none. 26 * 27 * @var array<string,string|null> 28 */ 19 /** @var array<string,string|null> */ 29 20 private array $seen = array(); 30 21 31 /** 32 * Hook into WordPress. 33 * 34 * @return void 35 */ 22 /** @return void */ 36 23 public function register(): void { 37 24 add_filter( 'the_content', array( $this, 'localize' ), 20 ); … … 39 26 40 27 /** 41 * Point the links of a translated page at translations.42 *43 28 * @param mixed $content Post content. 44 29 * @return mixed … … 64 49 65 50 /** 66 * The address a link should have in a language, or null to leave it alone.67 *68 * Only links to this site are considered, and only when the linked post has a published69 * translation. A link to a page nobody translated keeps working in the other language.70 *71 51 * @param string $href Address as written. 72 52 * @param string $language Language address prefix. … … 82 62 $key = $language . ' ' . $path; 83 63 if ( ! array_key_exists( $key, $this->seen ) ) { 84 // The lookup must see every language, so it runs as a request that is not a visitor's. 64 85 65 add_filter( 'vabelon_request_is_public', '__return_false', 99 ); 86 66 $post_id = url_to_postid( $path ); -
vabelon/trunk/src/Frontend/Hreflang.php
r3827447 r3830701 15 15 defined( 'ABSPATH' ) || exit; 16 16 17 /** 18 * Hreflang links. 19 */ 17 20 18 final class Hreflang { 21 19 22 /** 23 * Hook into WordPress. 24 * 25 * @return void 26 */ 20 /** @return void */ 27 21 public function register(): void { 28 22 add_action( 'wp_head', array( $this, 'output' ), 2 ); … … 30 24 31 25 /** 32 * Alternates of a post: one row per published translation, plus x-default.33 *34 26 * @param int $post_id Post ID. 35 27 * @return array<int,array{hreflang:string,href:string}> … … 44 36 } 45 37 46 /** 47 * Alternates of the home page. 48 * 49 * @return array<int,array{hreflang:string,href:string}> 50 */ 38 /** @return array<int,array{hreflang:string,href:string}> */ 51 39 public function home_model(): array { 52 40 if ( 'page' === get_option( 'show_on_front' ) ) { … … 62 50 63 51 /** 64 * The link elements for a list of alternates.65 *66 52 * @param array<int,array{hreflang:string,href:string}> $model Alternates. 67 53 * @return string … … 75 61 } 76 62 77 /** 78 * Print the alternates of the current page. 79 * 80 * @return void 81 */ 63 /** @return void */ 82 64 public function output(): void { 83 65 if ( is_404() || is_preview() || is_search() || is_archive() || is_paged() ) { … … 86 68 $model = array(); 87 69 if ( is_singular() || ( is_home() && ! is_front_page() ) ) { 88 // A posts page is a page too: its translations are the other languages' blog indexes. 70 89 71 $model = $this->singular_model( get_queried_object_id() ); 90 72 } elseif ( is_front_page() ) { … … 95 77 96 78 /** 97 * Rows in language order, with x-default pointing at the default language.98 *99 79 * @param array<string,string> $addresses Language address prefix => address. 100 80 * @return array<int,array{hreflang:string,href:string}> -
vabelon/trunk/src/Frontend/Locale.php
r3826639 r3830701 14 14 defined( 'ABSPATH' ) || exit; 15 15 16 /** 17 * Locale per language. 18 */ 16 19 17 final class Locale { 20 18 21 /** 22 * Whether the locale is being resolved right now. 23 * 24 * @var bool 25 */ 19 /** @var bool */ 26 20 private bool $resolving = false; 27 21 28 /** 29 * Hook into WordPress. 30 * 31 * @return void 32 */ 22 /** @return void */ 33 23 public function register(): void { 34 24 add_filter( 'determine_locale', array( $this, 'filter' ), 20 ); … … 37 27 38 28 /** 39 * The locale of the request's language.40 *41 29 * @param mixed $locale Locale WordPress chose. 42 30 * @return mixed -
vabelon/trunk/src/Frontend/Menus.php
r3827447 r3830701 14 14 defined( 'ABSPATH' ) || exit; 15 15 16 /** 17 * Navigation menus. 18 */ 16 19 17 final class Menus { 20 18 21 19 public const OPTION = 'vabelon_menu_locations'; 22 20 23 /** 24 * Hook into WordPress. 25 * 26 * @return void 27 */ 21 /** @return void */ 28 22 public function register(): void { 29 23 add_filter( 'theme_mod_nav_menu_locations', array( $this, 'filter_locations' ) ); … … 31 25 } 32 26 33 /** 34 * The stored choices: language address prefix => theme location => menu ID. 35 * 36 * @return array<string,array<string,int>> 37 */ 27 /** @return array<string,array<string,int>> */ 38 28 public static function map(): array { 39 29 $stored = get_option( self::OPTION, array() ); … … 50 40 51 41 /** 52 * Menu locations for the language of the request.53 *54 42 * @param mixed $locations Theme location => menu ID. 55 43 * @return mixed … … 60 48 61 49 /** 62 * Menu locations for a language.63 *64 * A language with no menus of its own uses the default language's. Once a language has65 * a menu, a location it leaves empty shows no menu on its pages.66 *67 50 * @param array<mixed> $locations Theme location => menu ID. 68 51 * @param string $language Language address prefix. … … 90 73 91 74 /** 92 * Menu items for the language of the request.93 *94 75 * @param mixed $items Menu items. 95 76 * @return mixed … … 100 81 101 82 /** 102 * Point each item that links a post at the post's published translation.103 *104 * An item whose post has no translation keeps its address.105 *106 83 * @param array<int|string,mixed> $items Menu items. 107 84 * @param string $language Language address prefix. -
vabelon/trunk/src/Frontend/Switcher.php
r3827447 r3830701 15 15 defined( 'ABSPATH' ) || exit; 16 16 17 /** 18 * Language switcher. 19 */ 17 20 18 final class Switcher { 21 19 … … 36 34 ); 37 35 38 /** 39 * Hook into WordPress. 40 * 41 * @return void 42 */ 36 /** @return void */ 43 37 public function register(): void { 44 38 add_shortcode( 'vabelon_switcher', array( $this, 'shortcode' ) ); … … 47 41 48 42 /** 49 * The links to show.50 *51 43 * @param int|null $post_id Post being viewed, or null on a page that is not one post. 52 44 * @param string $active Language of the page being viewed. … … 73 65 74 66 /** 75 * The switcher's markup; empty when there is nothing to switch to.76 *77 67 * @param array<int,array{slug:string,label:string,hreflang:string,url:string,is_current:bool}> $items Links. 78 68 * @return string … … 96 86 } 97 87 98 /** 99 * The switcher for the page being viewed. 100 * 101 * @return string 102 */ 88 /** @return string */ 103 89 public function shortcode(): string { 104 90 $post_id = is_singular() || ( is_home() && ! is_front_page() ) ? get_queried_object_id() : 0; … … 108 94 } 109 95 110 /** 111 * Print the switcher for the page being viewed. 112 * 113 * @return void 114 */ 96 /** @return void */ 115 97 public function output(): void { 116 98 echo wp_kses( $this->shortcode(), self::ALLOWED ); -
vabelon/trunk/src/Language/Language.php
r3826639 r3830701 12 12 defined( 'ABSPATH' ) || exit; 13 13 14 /** 15 * Description of a language. Built by Languages from validated rows. 16 */ 14 17 15 final class Language { 18 16 19 /** 20 * Address prefix, such as "es". 21 * 22 * @var string 23 */ 17 /** @var string */ 24 18 public string $slug; 25 19 26 /** 27 * WordPress locale, such as "es_ES". 28 * 29 * @var string 30 */ 20 /** @var string */ 31 21 public string $wp_locale; 32 22 33 /** 34 * Value for hreflang attributes, such as "es". 35 * 36 * @var string 37 */ 23 /** @var string */ 38 24 public string $hreflang; 39 25 40 /** 41 * Name in the site's language. 42 * 43 * @var string 44 */ 26 /** @var string */ 45 27 public string $name; 46 28 47 /** 48 * Name in the language itself. 49 * 50 * @var string 51 */ 29 /** @var string */ 52 30 public string $native_name; 53 31 54 /** 55 * Whether this is the site's default language. 56 * 57 * @var bool 58 */ 32 /** @var bool */ 59 33 public bool $is_default; 60 34 61 /** 62 * Constructor. 63 * 64 * @param array{slug:string,wp_locale:string,hreflang:string,name:string,native_name:string,is_default:bool} $row Validated row. 65 */ 35 /** @param array{slug:string,wp_locale:string,hreflang:string,name:string,native_name:string,is_default:bool} $row Validated row. */ 66 36 public function __construct( array $row ) { 67 37 $this->slug = $row['slug']; -
vabelon/trunk/src/Language/Languages.php
r3826639 r3830701 14 14 defined( 'ABSPATH' ) || exit; 15 15 16 /** 17 * Language registry. 18 */ 16 19 17 final class Languages { 20 18 … … 23 21 private const RESERVED = array( 'wp-admin', 'wp-json', 'wp-content', 'wp-includes', 'feed', 'page', 'author', 'category', 'tag', 'search', 'comments', 'embed' ); 24 22 25 /** 26 * Languages read during this request. 27 * 28 * @var array<int,Language>|null 29 */ 23 /** @var array<int,Language>|null */ 30 24 private ?array $cache = null; 31 25 32 /** 33 * Fingerprint of the stored option the cache was built from. 34 * 35 * @var string 36 */ 26 /** @var string */ 37 27 private string $cache_key = ''; 38 28 39 /** 40 * Every configured language, in stored order. 41 * 42 * @return array<int,Language> 43 */ 29 /** @return array<int,Language> */ 44 30 public function all(): array { 45 31 $stored = get_option( self::OPTION, array() ); … … 60 46 61 47 /** 62 * One language by its address prefix.63 *64 48 * @param string $slug Address prefix. 65 49 * @return Language|null … … 74 58 } 75 59 76 /** 77 * Address prefix of the default language, or '' when none is configured. 78 * 79 * @return string 80 */ 60 /** @return string */ 81 61 public function default_slug(): string { 82 62 foreach ( $this->all() as $language ) { … … 88 68 } 89 69 90 /** 91 * Address prefixes of every language except the default. 92 * 93 * @return array<int,string> 94 */ 70 /** @return array<int,string> */ 95 71 public function non_default_slugs(): array { 96 72 $slugs = array(); … … 104 80 105 81 /** 106 * Check and normalize a list of language rows. Writes nothing.107 *108 82 * @param array $rows Rows with slug, wp_locale, hreflang, name, native_name and is_default. 109 83 * @return array<int,array{slug:string,wp_locale:string,hreflang:string,name:string,native_name:string,is_default:bool}>|WP_Error … … 145 119 146 120 /** 147 * Save a list of language rows.148 *149 121 * @param array $rows Rows as accepted by validate(). 150 122 * @return true|WP_Error … … 167 139 } 168 140 169 /** 170 * On first activation, make the site's own language the default. 171 * 172 * @return void 173 */ 141 /** @return void */ 174 142 public function seed_from_site_locale(): void { 175 143 if ( false !== get_option( self::OPTION, false ) ) { … … 193 161 194 162 /** 195 * Name of the first field of a row that is not valid, or ''.196 *197 163 * @param array{slug:string,wp_locale:string,hreflang:string,name:string,native_name:string,is_default:bool} $item Row. 198 164 * @return string … … 217 183 218 184 /** 219 * A string from a scalar value; '' for anything else.220 *221 185 * @param mixed $value Value. 222 186 * @return string -
vabelon/trunk/src/Plugin.php
r3827447 r3830701 17 17 defined( 'ABSPATH' ) || exit; 18 18 19 /** 20 * Plugin bootstrap and the four objects every component shares. 21 */ 19 22 20 final class Plugin { 23 21 24 /** 25 * Shared objects, created on first use. 26 * 27 * @var array<string,object> 28 */ 22 /** @var array<string,object> */ 29 23 private static array $shared = array(); 30 24 31 /** 32 * Register every component once. 33 * 34 * @return void 35 */ 25 /** @return void */ 36 26 public static function boot(): void { 37 27 if ( isset( self::$shared['booted'] ) ) { … … 57 47 } 58 48 59 /** 60 * The language registry. 61 * 62 * @return Languages 63 */ 49 /** @return Languages */ 64 50 public static function languages(): Languages { 65 51 $found = self::$shared['languages'] ?? null; … … 71 57 } 72 58 73 /** 74 * The translation storage. 75 * 76 * @return Translations 77 */ 59 /** @return Translations */ 78 60 public static function translations(): Translations { 79 61 $found = self::$shared['translations'] ?? null; … … 85 67 } 86 68 87 /** 88 * The language addresses. 89 * 90 * @return Urls 91 */ 69 /** @return Urls */ 92 70 public static function urls(): Urls { 93 71 $found = self::$shared['urls'] ?? null; … … 99 77 } 100 78 101 /** 102 * The request language. 103 * 104 * @return Request 105 */ 79 /** @return Request */ 106 80 public static function request(): Request { 107 81 $found = self::$shared['request'] ?? null; … … 113 87 } 114 88 115 /** 116 * Activation: make the site's language the default and rebuild the routes on the next request. 117 * 118 * @return void 119 */ 89 /** @return void */ 120 90 public static function activate(): void { 121 91 self::languages()->seed_from_site_locale(); … … 123 93 } 124 94 125 /** 126 * Deactivation: let WordPress rebuild its rules without the language routes. 127 * 128 * @return void 129 */ 95 /** @return void */ 130 96 public static function deactivate(): void { 131 97 delete_option( 'vabelon_rewrite_signature' ); -
vabelon/trunk/src/Routing/Permalinks.php
r3826639 r3830701 15 15 defined( 'ABSPATH' ) || exit; 16 16 17 /** 18 * Permalink filters. 19 */ 17 20 18 final class Permalinks { 21 19 22 20 private const ARCHIVE_FILTERS = array( 'post_type_archive_link', 'search_link', 'feed_link', 'year_link', 'month_link', 'day_link', 'author_link', 'get_pagenum_link', 'term_link' ); 23 21 24 /** 25 * Whether home_url() is being filtered right now. 26 * 27 * @var bool 28 */ 22 /** @var bool */ 29 23 private bool $filtering_home = false; 30 24 31 /** 32 * Hook the filters into WordPress. 33 * 34 * @return void 35 */ 25 /** @return void */ 36 26 public function register(): void { 37 27 foreach ( array( 'post_link', 'page_link', 'post_type_link' ) as $filter ) { … … 45 35 46 36 /** 47 * Address of a post, in the post's own language.48 *49 37 * @param mixed $url Address WordPress built. 50 38 * @param mixed $post Post object or ID. … … 61 49 62 50 /** 63 * Address of an archive, search or feed, in the language of the request.64 *65 51 * @param mixed $url Address WordPress built. 66 52 * @return mixed … … 74 60 75 61 /** 76 * The home address, in the language of the request.77 *78 62 * @param mixed $url Address WordPress built. 79 63 * @param mixed $path Path that was asked for. -
vabelon/trunk/src/Routing/QueryLanguage.php
r3827447 r3830701 18 18 defined( 'ABSPATH' ) || exit; 19 19 20 /** 21 * Query scoping. 22 */ 20 23 21 final class QueryLanguage { 24 22 25 /** 26 * Hook the scoping into WordPress. 27 * 28 * @return void 29 */ 23 /** @return void */ 30 24 public function register(): void { 31 25 add_action( 'pre_get_posts', array( $this, 'scope' ), 1 ); … … 35 29 36 30 /** 37 * Limit a list query to one language.38 *39 * A request for one specific post is left alone: StaticPages sends it to its own address.40 *41 31 * @param WP_Query $query Query about to run. 42 32 * @return void … … 47 37 return; 48 38 } 49 // WordPress leaves the post type empty on the blog index, search, feeds and most archives. 39 50 40 $types = array_filter( 51 41 (array) $query->get( 'post_type' ), … … 76 66 77 67 /** 78 * Keep the previous and next post links inside the language of the post being viewed.79 *80 68 * @param mixed $where WHERE clause of the adjacent post query; the posts table is aliased p. 81 69 * @param mixed $same Unused. … … 103 91 return $default ? $where : $where . ' AND 1 = 0'; 104 92 } 105 // $ids holds integers only, read from the language terms above. 93 106 94 return $where . ' AND p.ID ' . ( $default ? 'NOT IN' : 'IN' ) . " ( SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN ( " . implode( ',', $ids ) . ' ) )'; 107 95 } -
vabelon/trunk/src/Routing/Request.php
r3826639 r3830701 14 14 defined( 'ABSPATH' ) || exit; 15 15 16 /** 17 * Request language. 18 */ 16 19 17 final class Request { 20 18 21 /** 22 * Language resolved for this request. 23 * 24 * @var string|null 25 */ 19 /** @var string|null */ 26 20 private ?string $resolved = null; 27 21 28 /** 29 * Address prefix of the language this request is for. 30 * 31 * @return string 32 */ 22 /** @return string */ 33 23 public function language(): string { 34 24 if ( ! $this->is_public() ) { … … 43 33 44 34 /** 45 * The language an address belongs to.46 *47 35 * @param string $uri Request address, path first. 48 36 * @return string … … 52 40 } 53 41 54 /** 55 * Whether this is a visitor-facing page request. 56 * 57 * @return bool 58 */ 42 /** @return bool */ 59 43 public function is_public(): bool { 60 44 global $pagenow; … … 69 53 } 70 54 71 /** 72 * The site's home address as stored, without a trailing slash. 73 * 74 * @return string 75 */ 55 /** @return string */ 76 56 public static function home(): string { 77 57 $home = get_option( 'home', '' ); -
vabelon/trunk/src/Routing/Rewrites.php
r3827447 r3830701 14 14 defined( 'ABSPATH' ) || exit; 15 15 16 /** 17 * Rewrite rules. 18 */ 16 19 17 final class Rewrites { 20 18 21 19 private const FAMILIES = array( 'post', 'page', 'date', 'author', 'search', 'root', 'category', 'post_tag' ); 22 20 23 /** 24 * Hook the rules into WordPress. 25 * 26 * @return void 27 */ 21 /** @return void */ 28 22 public function register(): void { 29 23 add_filter( 'query_vars', array( $this, 'query_vars' ) ); … … 38 32 39 33 /** 40 * Allow the language in the query.41 *42 34 * @param array<int,string> $vars Public query variables. 43 35 * @return array<int,string> … … 49 41 50 42 /** 51 * Add a copy of each rule that starts with a language prefix.52 *53 43 * @param array<string,string> $rules Rules of one family. 54 44 * @return array<string,string> … … 79 69 } 80 70 81 /** 82 * Add the rule for each language's home address. 83 * 84 * @return void 85 */ 71 /** @return void */ 86 72 public function add_home_rule(): void { 87 73 $group = $this->language_group(); … … 91 77 } 92 78 93 /** 94 * Rebuild WordPress's rules when the languages or the address structure changed. 95 * 96 * @return void 97 */ 79 /** @return void */ 98 80 public function maybe_flush(): void { 99 81 $signature = hash( 'sha256', (string) wp_json_encode( array( VABELON_VERSION, Plugin::languages()->all(), get_option( 'permalink_structure', '' ) ) ) ); … … 106 88 107 89 /** 108 * Stop WordPress redirecting a language address to another language.109 *110 90 * @param mixed $redirect Address WordPress wants to redirect to. 111 91 * @param mixed $requested Address that was requested. … … 123 103 } 124 104 125 /** 126 * Give a language home one address: with or without the trailing slash, as the permalink structure says. 127 * 128 * @return void 129 */ 105 /** @return void */ 130 106 public function home_slash(): void { 131 107 $method = isset( $_SERVER['REQUEST_METHOD'] ) && is_string( $_SERVER['REQUEST_METHOD'] ) ? sanitize_key( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) : ''; … … 147 123 } 148 124 149 /** 150 * Regex group matching every language prefix except the default, followed by a slash. 151 * 152 * @return string 153 */ 125 /** @return string */ 154 126 private function language_group(): string { 155 127 $slugs = Plugin::languages()->non_default_slugs(); -
vabelon/trunk/src/Routing/StaticPages.php
r3827447 r3830701 15 15 defined( 'ABSPATH' ) || exit; 16 16 17 /** 18 * Static front page and posts page per language. 19 */ 17 20 18 final class StaticPages { 21 19 22 /** 23 * Whether the front page option is being read unfiltered. 24 * 25 * @var bool 26 */ 20 /** @var bool */ 27 21 private static bool $reading_original = false; 28 22 29 /** 30 * Hook into WordPress. 31 * 32 * @return void 33 */ 23 /** @return void */ 34 24 public function register(): void { 35 25 add_filter( 'option_page_on_front', array( $this, 'front_page_id' ) ); … … 39 29 } 40 30 41 /** 42 * The front page chosen in Settings > Reading, in the default language. 43 * 44 * @return int 45 */ 31 /** @return int */ 46 32 public static function original_front(): int { 47 33 self::$reading_original = true; … … 52 38 53 39 /** 54 * On a language address, the front page and the posts page are their translations in that language.55 *56 * WordPress then treats a request for the translated posts page as that language's blog index.57 *58 40 * @param mixed $value Stored page ID. 59 41 * @return mixed … … 72 54 73 55 /** 74 * Turn a language home request into a request for that language's front page.75 *76 56 * @param WP_Query $query Query about to run. 77 57 * @return void … … 101 81 } 102 82 103 /** 104 * Send a request for a post in another language to the post's own address. 105 * 106 * @return void 107 */ 83 /** @return void */ 108 84 public function redirect_to_language(): void { 109 85 if ( ! is_singular() || is_preview() ) { -
vabelon/trunk/src/Routing/Urls.php
r3827447 r3830701 14 14 defined( 'ABSPATH' ) || exit; 15 15 16 /** 17 * Language addresses. 18 */ 16 19 17 final class Urls { 20 18 21 19 /** 22 * Home address of a language.23 *24 20 * @param string $slug Language address prefix. 25 21 * @return string … … 30 26 31 27 /** 32 * Whether a post is the front page or one of its translations.33 *34 28 * @param int $post_id Post ID. 35 29 * @return bool … … 44 38 45 39 /** 46 * Put an address into a language.47 *48 40 * @param string $url Address on this site. 49 41 * @param string $slug Language address prefix. … … 76 68 77 69 /** 78 * The language an address belongs to.79 *80 70 * @param string $url Address. 81 71 * @return string … … 89 79 90 80 /** 91 * End a path the way the site's permalink structure does.92 *93 * Addresses are also built before WordPress sets up its rewrite object, where94 * user_trailingslashit() cannot be called.95 *96 81 * @param string $path Path without a trailing slash. 97 82 * @return string … … 106 91 107 92 /** 108 * A path relative to the home path, with any language prefix removed.109 *110 93 * @param string $path Path of an address. 111 94 * @param string $base Path of the home address. … … 130 113 131 114 /** 132 * Whether a parsed address is on this site.133 *134 115 * @param array<string,int|string> $parts Parsed address. 135 116 * @return bool -
vabelon/trunk/vabelon.php
r3827447 r3830701 3 3 * Plugin Name: Vabelon: Lightweight Multilingual, Hreflang Tags & Language Switcher 4 4 * Description: Multilingual WordPress in a small plugin: languages, translated addresses, hreflang and a language switcher. 5 * Version: 26.11.2 6.105 * Version: 26.11.27.19 6 6 * Requires at least: 6.2 7 7 * Requires PHP: 7.4 … … 20 20 defined( 'ABSPATH' ) || exit; 21 21 22 define( 'VABELON_VERSION', '26.11.2 6.10' );22 define( 'VABELON_VERSION', '26.11.27.19' ); 23 23 define( 'VABELON_FILE', __FILE__ ); 24 24 define( 'VABELON_PATH', plugin_dir_path( __FILE__ ) ); … … 40 40 add_action( 'plugins_loaded', array( \Vabelon\Plugin::class, 'boot' ) ); 41 41 42 /** 43 * Print the language switcher. For use in theme templates. 44 * 45 * @return void 46 */ 42 /** @return void */ 47 43 function vabelon_switcher(): void { 48 44 do_action( 'vabelon_switcher' ); 49 45 } 50 46 51 /** 52 * Address prefix of the language the current request is for. 53 * 54 * @return string 55 */ 47 /** @return string */ 56 48 function vabelon_current_language(): string { 57 49 return \Vabelon\Plugin::request()->language(); 58 50 } 59 51 60 /** 61 * The configured languages, default first: slug, wp_locale, hreflang, name, native_name, is_default. 62 * 63 * @return array<int,array<string,mixed>> 64 */ 52 /** @return array<int,array<string,mixed>> */ 65 53 function vabelon_languages(): array { 66 54 return array_values( array_map( 'get_object_vars', \Vabelon\Plugin::languages()->all() ) ); … … 68 56 69 57 /** 70 * The language a post was given, or null when it has none and is shown as the default language.71 *72 58 * @param int $post_id Post ID. 73 59 * @return string|null … … 78 64 79 65 /** 80 * A post and its translations, as language address prefix => post ID.81 *82 66 * @param int $post_id Post ID. 83 67 * @param array<int,string> $statuses Keep only posts with one of these statuses; empty keeps all.
Note:
See TracChangeset
for help on using the changeset viewer.