Plugin Directory

Changeset 3830701


Ignore:
Timestamp:
11/28/2026 01:28:33 AM (less than one hour ago)
Author:
rnzo
Message:

Bug fixes

Location:
vabelon
Files:
40 edited
1 copied

Legend:

Unmodified
Added
Removed
  • vabelon/tags/26.11.27.19/languages/vabelon.pot

    r3827447 r3830701  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Vabelon: Lightweight Multilingual, Hreflang Tags & Language Switcher 26.11.26.10\n"
     5"Project-Id-Version: Vabelon: Lightweight Multilingual, Hreflang Tags & Language Switcher 26.11.27.19\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/vabelon\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
  • vabelon/tags/26.11.27.19/readme.txt

    r3827588 r3830701  
    55Tested up to: 7.1
    66Requires PHP: 7.4
    7 Stable tag: 26.11.26.10
     7Stable tag: 26.11.27.19
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    110110[View the complete release history](https://vabelon.com/changelog).
    111111
     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
    112116= 26.11.26.10 =
    113117
  • vabelon/tags/26.11.27.19/src/Admin/Settings.php

    r3827447 r3830701  
    1616defined( 'ABSPATH' ) || exit;
    1717
    18 /**
    19  * Settings page, built on the WordPress Settings API.
    20  */
     18
    2119final class Settings {
    2220
    … …  
    2422        public const GROUP = 'vabelon';
    2523
    26         /**
    27          * Hook the page into WordPress.
    28          *
    29          * @return void
    30          */
     24        /** @return void */
    3125        public function register(): void {
    3226                add_action( 'admin_menu', array( $this, 'menu' ) );
    … …  
    3630
    3731        /**
    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          *
    4232         * @param mixed $plugins Plugins keyed by basename.
    4333         * @return mixed
    … …  
    5141        }
    5242
    53         /**
    54          * Add the page under Settings.
    55          *
    56          * @return void
    57          */
     43        /** @return void */
    5844        public function menu(): void {
    5945                add_options_page( 'Vabelon', 'Vabelon', 'manage_options', self::PAGE, array( $this, 'render' ) );
    6046        }
    6147
    62         /**
    63          * Register the option with the Settings API.
    64          *
    65          * @return void
    66          */
     48        /** @return void */
    6749        public function setting(): void {
    6850                register_setting(
    … …  
    8769
    8870        /**
    89          * Keep only menu choices for a configured language, a theme location and a menu that exists.
    90          *
    9171         * @param mixed $input Submitted choices: language => location => menu ID.
    9272         * @return array<string,array<string,int>>
    … …  
    11292        }
    11393
    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 */
    12195        private function menus_table(): void {
    12296                $locations = get_registered_nav_menus();
    … …  
    149123
    150124        /**
    151          * Validate and sanitize the value before it is stored.
    152          *
    153          * Accepts the settings form (rows and default) or the stored shape (items), which
    154          * Languages::save() passes through update_option(). Both are validated the same way.
    155          *
    156125         * @param mixed $input Submitted form or stored shape.
    157126         * @return mixed The value to store.
    … …  
    175144
    176145        /**
    177          * Language rows from the settings form: removed and empty rows are dropped, and
    178          * the chosen radio button marks the default.
    179          *
    180146         * @param array $input Submitted form.
    181147         * @return array<int,array>
    … …  
    198164        }
    199165
    200         /**
    201          * Print the page.
    202          *
    203          * @return void
    204          */
     166        /** @return void */
    205167        public function render(): void {
    206168                if ( ! current_user_can( 'manage_options' ) ) {
    … …  
    232194                        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>';
    233195                        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>';
    235197                        }
    236198                        echo '<td>';
  • vabelon/tags/26.11.27.19/src/Admin/TranslationsBox.php

    r3826639 r3830701  
    1616defined( 'ABSPATH' ) || exit;
    1717
    18 /**
    19  * Editor meta box.
    20  */
     18
    2119final class TranslationsBox {
    2220
    23         /**
    24          * Hook the box into WordPress.
    25          *
    26          * @return void
    27          */
     21        /** @return void */
    2822        public function register(): void {
    2923                add_action( 'add_meta_boxes', array( $this, 'add' ) );
    … …  
    3226        }
    3327
    34         /**
    35          * Add the box to every supported post type.
    36          *
    37          * @return void
    38          */
     28        /** @return void */
    3929        public function add(): void {
    4030                foreach ( Plugin::translations()->post_types() as $type ) {
    … …  
    4434
    4535        /**
    46          * Print the box.
    47          *
    4836         * @param WP_Post $post Post being edited.
    4937         * @return void
    … …  
    7563
    7664        /**
    77          * Save the box.
    78          *
    7965         * @param int     $post_id Post ID.
    8066         * @param WP_Post $post    Post being saved.
    … …  
    10389
    10490        /**
    105          * Apply the box's choices to a post.
    106          *
    10791         * @param int               $post_id  Post ID.
    10892         * @param string            $language Chosen language.
    … …  
    137121        }
    138122
    139         /**
    140          * Show the last error once.
    141          *
    142          * @return void
    143          */
     123        /** @return void */
    144124        public function notice(): void {
    145125                $key     = 'vabelon_box_error_' . get_current_user_id();
  • vabelon/tags/26.11.27.19/src/Content/Translations.php

    r3826639 r3830701  
    1818defined( 'ABSPATH' ) || exit;
    1919
    20 /**
    21  * Reads and writes the two taxonomies.
    22  */
     20
    2321final class Translations {
    2422
    … …  
    2624        public const GROUP    = 'vabelon_group';
    2725
    28         /**
    29          * Hook the taxonomies into WordPress.
    30          *
    31          * @return void
    32          */
     26        /** @return void */
    3327        public function register(): void {
    3428                add_action( 'init', array( $this, 'register_taxonomies' ), 5 );
    3529        }
    3630
    37         /**
    38          * Register both hidden taxonomies.
    39          *
    40          * @return void
    41          */
     31        /** @return void */
    4232        public function register_taxonomies(): void {
    4333                foreach ( array( self::LANGUAGE, self::GROUP ) as $taxonomy ) {
    … …  
    5444        }
    5545
    56         /**
    57          * Post types that can have a language.
    58          *
    59          * @return array<int,string>
    60          */
     46        /** @return array<int,string> */
    6147        public function post_types(): array {
    6248                $types = apply_filters( 'vabelon_post_types', array( 'post', 'page' ) );
    … …  
    6652
    6753        /**
    68          * Whether a post can have a language.
    69          *
    7054         * @param int $post_id Post ID.
    7155         * @return bool
    … …  
    7761
    7862        /**
    79          * The language a post was given, or null.
    80          *
    8163         * @param int $post_id Post ID.
    8264         * @return string|null
    … …  
    8870
    8971        /**
    90          * The language a post is shown in: its own, or the default.
    91          *
    9272         * @param int $post_id Post ID.
    9373         * @return string
    … …  
    9979
    10080        /**
    101          * Give a post a language.
    102          *
    10381         * @param int    $post_id Post ID.
    10482         * @param string $slug    Language address prefix.
    … …  
    11492
    11593        /**
    116          * The translation group of a post, or null.
    117          *
    11894         * @param int $post_id Post ID.
    11995         * @return string|null
    … …  
    124100
    125101        /**
    126          * A post and its translations, as language => post ID.
    127          *
    128102         * @param int               $post_id  Post ID.
    129103         * @param array<int,string> $statuses Keep only posts with one of these statuses; empty keeps all.
    … …  
    152126
    153127        /**
    154          * Link a post as the translation of another, in a language.
    155          *
    156128         * @param int    $source   Post that already exists in its language.
    157129         * @param int    $target   Post that becomes the translation.
    … …  
    195167
    196168        /**
    197          * Take a post out of its translation group.
    198          *
    199169         * @param int $post_id Post ID.
    200170         * @return bool Whether the post was in a group.
    … …  
    221191
    222192        /**
    223          * Slug of the first term a post has in a taxonomy, or null.
    224          *
    225193         * @param int    $post_id  Post ID.
    226194         * @param string $taxonomy Taxonomy name.
  • vabelon/tags/26.11.27.19/src/Frontend/ContentLinks.php

    r3827447 r3830701  
    1414defined( 'ABSPATH' ) || exit;
    1515
    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
    2217final class ContentLinks {
    2318
    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> */
    2920        private array $seen = array();
    3021
    31         /**
    32          * Hook into WordPress.
    33          *
    34          * @return void
    35          */
     22        /** @return void */
    3623        public function register(): void {
    3724                add_filter( 'the_content', array( $this, 'localize' ), 20 );
    … …  
    3926
    4027        /**
    41          * Point the links of a translated page at translations.
    42          *
    4328         * @param mixed $content Post content.
    4429         * @return mixed
    … …  
    6449
    6550        /**
    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 published
    69          * translation. A link to a page nobody translated keeps working in the other language.
    70          *
    7151         * @param string $href     Address as written.
    7252         * @param string $language Language address prefix.
    … …  
    8262                $key = $language . ' ' . $path;
    8363                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
    8565                        add_filter( 'vabelon_request_is_public', '__return_false', 99 );
    8666                        $post_id = url_to_postid( $path );
  • vabelon/tags/26.11.27.19/src/Frontend/Hreflang.php

    r3827447 r3830701  
    1515defined( 'ABSPATH' ) || exit;
    1616
    17 /**
    18  * Hreflang links.
    19  */
     17
    2018final class Hreflang {
    2119
    22         /**
    23          * Hook into WordPress.
    24          *
    25          * @return void
    26          */
     20        /** @return void */
    2721        public function register(): void {
    2822                add_action( 'wp_head', array( $this, 'output' ), 2 );
    … …  
    3024
    3125        /**
    32          * Alternates of a post: one row per published translation, plus x-default.
    33          *
    3426         * @param int $post_id Post ID.
    3527         * @return array<int,array{hreflang:string,href:string}>
    … …  
    4436        }
    4537
    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}> */
    5139        public function home_model(): array {
    5240                if ( 'page' === get_option( 'show_on_front' ) ) {
    … …  
    6250
    6351        /**
    64          * The link elements for a list of alternates.
    65          *
    6652         * @param array<int,array{hreflang:string,href:string}> $model Alternates.
    6753         * @return string
    … …  
    7561        }
    7662
    77         /**
    78          * Print the alternates of the current page.
    79          *
    80          * @return void
    81          */
     63        /** @return void */
    8264        public function output(): void {
    8365                if ( is_404() || is_preview() || is_search() || is_archive() || is_paged() ) {
    … …  
    8668                $model = array();
    8769                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
    8971                        $model = $this->singular_model( get_queried_object_id() );
    9072                } elseif ( is_front_page() ) {
    … …  
    9577
    9678        /**
    97          * Rows in language order, with x-default pointing at the default language.
    98          *
    9979         * @param array<string,string> $addresses Language address prefix => address.
    10080         * @return array<int,array{hreflang:string,href:string}>
  • vabelon/tags/26.11.27.19/src/Frontend/Locale.php

    r3826639 r3830701  
    1414defined( 'ABSPATH' ) || exit;
    1515
    16 /**
    17  * Locale per language.
    18  */
     16
    1917final class Locale {
    2018
    21         /**
    22          * Whether the locale is being resolved right now.
    23          *
    24          * @var bool
    25          */
     19        /** @var bool */
    2620        private bool $resolving = false;
    2721
    28         /**
    29          * Hook into WordPress.
    30          *
    31          * @return void
    32          */
     22        /** @return void */
    3323        public function register(): void {
    3424                add_filter( 'determine_locale', array( $this, 'filter' ), 20 );
    … …  
    3727
    3828        /**
    39          * The locale of the request's language.
    40          *
    4129         * @param mixed $locale Locale WordPress chose.
    4230         * @return mixed
  • vabelon/tags/26.11.27.19/src/Frontend/Menus.php

    r3827447 r3830701  
    1414defined( 'ABSPATH' ) || exit;
    1515
    16 /**
    17  * Navigation menus.
    18  */
     16
    1917final class Menus {
    2018
    2119        public const OPTION = 'vabelon_menu_locations';
    2220
    23         /**
    24          * Hook into WordPress.
    25          *
    26          * @return void
    27          */
     21        /** @return void */
    2822        public function register(): void {
    2923                add_filter( 'theme_mod_nav_menu_locations', array( $this, 'filter_locations' ) );
    … …  
    3125        }
    3226
    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>> */
    3828        public static function map(): array {
    3929                $stored = get_option( self::OPTION, array() );
    … …  
    5040
    5141        /**
    52          * Menu locations for the language of the request.
    53          *
    5442         * @param mixed $locations Theme location => menu ID.
    5543         * @return mixed
    … …  
    6048
    6149        /**
    62          * Menu locations for a language.
    63          *
    64          * A language with no menus of its own uses the default language's. Once a language has
    65          * a menu, a location it leaves empty shows no menu on its pages.
    66          *
    6750         * @param array<mixed> $locations Theme location => menu ID.
    6851         * @param string       $language  Language address prefix.
    … …  
    9073
    9174        /**
    92          * Menu items for the language of the request.
    93          *
    9475         * @param mixed $items Menu items.
    9576         * @return mixed
    … …  
    10081
    10182        /**
    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          *
    10683         * @param array<int|string,mixed> $items    Menu items.
    10784         * @param string                  $language Language address prefix.
  • vabelon/tags/26.11.27.19/src/Frontend/Switcher.php

    r3827447 r3830701  
    1515defined( 'ABSPATH' ) || exit;
    1616
    17 /**
    18  * Language switcher.
    19  */
     17
    2018final class Switcher {
    2119
    … …  
    3634        );
    3735
    38         /**
    39          * Hook into WordPress.
    40          *
    41          * @return void
    42          */
     36        /** @return void */
    4337        public function register(): void {
    4438                add_shortcode( 'vabelon_switcher', array( $this, 'shortcode' ) );
    … …  
    4741
    4842        /**
    49          * The links to show.
    50          *
    5143         * @param int|null $post_id Post being viewed, or null on a page that is not one post.
    5244         * @param string   $active  Language of the page being viewed.
    … …  
    7365
    7466        /**
    75          * The switcher's markup; empty when there is nothing to switch to.
    76          *
    7767         * @param array<int,array{slug:string,label:string,hreflang:string,url:string,is_current:bool}> $items Links.
    7868         * @return string
    … …  
    9686        }
    9787
    98         /**
    99          * The switcher for the page being viewed.
    100          *
    101          * @return string
    102          */
     88        /** @return string */
    10389        public function shortcode(): string {
    10490                $post_id = is_singular() || ( is_home() && ! is_front_page() ) ? get_queried_object_id() : 0;
    … …  
    10894        }
    10995
    110         /**
    111          * Print the switcher for the page being viewed.
    112          *
    113          * @return void
    114          */
     96        /** @return void */
    11597        public function output(): void {
    11698                echo wp_kses( $this->shortcode(), self::ALLOWED );
  • vabelon/tags/26.11.27.19/src/Language/Language.php

    r3826639 r3830701  
    1212defined( 'ABSPATH' ) || exit;
    1313
    14 /**
    15  * Description of a language. Built by Languages from validated rows.
    16  */
     14
    1715final class Language {
    1816
    19         /**
    20          * Address prefix, such as "es".
    21          *
    22          * @var string
    23          */
     17        /** @var string */
    2418        public string $slug;
    2519
    26         /**
    27          * WordPress locale, such as "es_ES".
    28          *
    29          * @var string
    30          */
     20        /** @var string */
    3121        public string $wp_locale;
    3222
    33         /**
    34          * Value for hreflang attributes, such as "es".
    35          *
    36          * @var string
    37          */
     23        /** @var string */
    3824        public string $hreflang;
    3925
    40         /**
    41          * Name in the site's language.
    42          *
    43          * @var string
    44          */
     26        /** @var string */
    4527        public string $name;
    4628
    47         /**
    48          * Name in the language itself.
    49          *
    50          * @var string
    51          */
     29        /** @var string */
    5230        public string $native_name;
    5331
    54         /**
    55          * Whether this is the site's default language.
    56          *
    57          * @var bool
    58          */
     32        /** @var bool */
    5933        public bool $is_default;
    6034
    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. */
    6636        public function __construct( array $row ) {
    6737                $this->slug        = $row['slug'];
  • vabelon/tags/26.11.27.19/src/Language/Languages.php

    r3826639 r3830701  
    1414defined( 'ABSPATH' ) || exit;
    1515
    16 /**
    17  * Language registry.
    18  */
     16
    1917final class Languages {
    2018
    … …  
    2321        private const RESERVED = array( 'wp-admin', 'wp-json', 'wp-content', 'wp-includes', 'feed', 'page', 'author', 'category', 'tag', 'search', 'comments', 'embed' );
    2422
    25         /**
    26          * Languages read during this request.
    27          *
    28          * @var array<int,Language>|null
    29          */
     23        /** @var array<int,Language>|null */
    3024        private ?array $cache = null;
    3125
    32         /**
    33          * Fingerprint of the stored option the cache was built from.
    34          *
    35          * @var string
    36          */
     26        /** @var string */
    3727        private string $cache_key = '';
    3828
    39         /**
    40          * Every configured language, in stored order.
    41          *
    42          * @return array<int,Language>
    43          */
     29        /** @return array<int,Language> */
    4430        public function all(): array {
    4531                $stored = get_option( self::OPTION, array() );
    … …  
    6046
    6147        /**
    62          * One language by its address prefix.
    63          *
    6448         * @param string $slug Address prefix.
    6549         * @return Language|null
    … …  
    7458        }
    7559
    76         /**
    77          * Address prefix of the default language, or '' when none is configured.
    78          *
    79          * @return string
    80          */
     60        /** @return string */
    8161        public function default_slug(): string {
    8262                foreach ( $this->all() as $language ) {
    … …  
    8868        }
    8969
    90         /**
    91          * Address prefixes of every language except the default.
    92          *
    93          * @return array<int,string>
    94          */
     70        /** @return array<int,string> */
    9571        public function non_default_slugs(): array {
    9672                $slugs = array();
    … …  
    10480
    10581        /**
    106          * Check and normalize a list of language rows. Writes nothing.
    107          *
    10882         * @param array $rows Rows with slug, wp_locale, hreflang, name, native_name and is_default.
    10983         * @return array<int,array{slug:string,wp_locale:string,hreflang:string,name:string,native_name:string,is_default:bool}>|WP_Error
    … …  
    145119
    146120        /**
    147          * Save a list of language rows.
    148          *
    149121         * @param array $rows Rows as accepted by validate().
    150122         * @return true|WP_Error
    … …  
    167139        }
    168140
    169         /**
    170          * On first activation, make the site's own language the default.
    171          *
    172          * @return void
    173          */
     141        /** @return void */
    174142        public function seed_from_site_locale(): void {
    175143                if ( false !== get_option( self::OPTION, false ) ) {
    … …  
    193161
    194162        /**
    195          * Name of the first field of a row that is not valid, or ''.
    196          *
    197163         * @param array{slug:string,wp_locale:string,hreflang:string,name:string,native_name:string,is_default:bool} $item Row.
    198164         * @return string
    … …  
    217183
    218184        /**
    219          * A string from a scalar value; '' for anything else.
    220          *
    221185         * @param mixed $value Value.
    222186         * @return string
  • vabelon/tags/26.11.27.19/src/Plugin.php

    r3827447 r3830701  
    1717defined( 'ABSPATH' ) || exit;
    1818
    19 /**
    20  * Plugin bootstrap and the four objects every component shares.
    21  */
     19
    2220final class Plugin {
    2321
    24         /**
    25          * Shared objects, created on first use.
    26          *
    27          * @var array<string,object>
    28          */
     22        /** @var array<string,object> */
    2923        private static array $shared = array();
    3024
    31         /**
    32          * Register every component once.
    33          *
    34          * @return void
    35          */
     25        /** @return void */
    3626        public static function boot(): void {
    3727                if ( isset( self::$shared['booted'] ) ) {
    … …  
    5747        }
    5848
    59         /**
    60          * The language registry.
    61          *
    62          * @return Languages
    63          */
     49        /** @return Languages */
    6450        public static function languages(): Languages {
    6551                $found = self::$shared['languages'] ?? null;
    … …  
    7157        }
    7258
    73         /**
    74          * The translation storage.
    75          *
    76          * @return Translations
    77          */
     59        /** @return Translations */
    7860        public static function translations(): Translations {
    7961                $found = self::$shared['translations'] ?? null;
    … …  
    8567        }
    8668
    87         /**
    88          * The language addresses.
    89          *
    90          * @return Urls
    91          */
     69        /** @return Urls */
    9270        public static function urls(): Urls {
    9371                $found = self::$shared['urls'] ?? null;
    … …  
    9977        }
    10078
    101         /**
    102          * The request language.
    103          *
    104          * @return Request
    105          */
     79        /** @return Request */
    10680        public static function request(): Request {
    10781                $found = self::$shared['request'] ?? null;
    … …  
    11387        }
    11488
    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 */
    12090        public static function activate(): void {
    12191                self::languages()->seed_from_site_locale();
    … …  
    12393        }
    12494
    125         /**
    126          * Deactivation: let WordPress rebuild its rules without the language routes.
    127          *
    128          * @return void
    129          */
     95        /** @return void */
    13096        public static function deactivate(): void {
    13197                delete_option( 'vabelon_rewrite_signature' );
  • vabelon/tags/26.11.27.19/src/Routing/Permalinks.php

    r3826639 r3830701  
    1515defined( 'ABSPATH' ) || exit;
    1616
    17 /**
    18  * Permalink filters.
    19  */
     17
    2018final class Permalinks {
    2119
    2220        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' );
    2321
    24         /**
    25          * Whether home_url() is being filtered right now.
    26          *
    27          * @var bool
    28          */
     22        /** @var bool */
    2923        private bool $filtering_home = false;
    3024
    31         /**
    32          * Hook the filters into WordPress.
    33          *
    34          * @return void
    35          */
     25        /** @return void */
    3626        public function register(): void {
    3727                foreach ( array( 'post_link', 'page_link', 'post_type_link' ) as $filter ) {
    … …  
    4535
    4636        /**
    47          * Address of a post, in the post's own language.
    48          *
    4937         * @param mixed $url  Address WordPress built.
    5038         * @param mixed $post Post object or ID.
    … …  
    6149
    6250        /**
    63          * Address of an archive, search or feed, in the language of the request.
    64          *
    6551         * @param mixed $url Address WordPress built.
    6652         * @return mixed
    … …  
    7460
    7561        /**
    76          * The home address, in the language of the request.
    77          *
    7862         * @param mixed $url  Address WordPress built.
    7963         * @param mixed $path Path that was asked for.
  • vabelon/tags/26.11.27.19/src/Routing/QueryLanguage.php

    r3827447 r3830701  
    1818defined( 'ABSPATH' ) || exit;
    1919
    20 /**
    21  * Query scoping.
    22  */
     20
    2321final class QueryLanguage {
    2422
    25         /**
    26          * Hook the scoping into WordPress.
    27          *
    28          * @return void
    29          */
     23        /** @return void */
    3024        public function register(): void {
    3125                add_action( 'pre_get_posts', array( $this, 'scope' ), 1 );
    … …  
    3529
    3630        /**
    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          *
    4131         * @param WP_Query $query Query about to run.
    4232         * @return void
    … …  
    4737                        return;
    4838                }
    49                 // WordPress leaves the post type empty on the blog index, search, feeds and most archives.
     39
    5040                $types = array_filter(
    5141                        (array) $query->get( 'post_type' ),
    … …  
    7666
    7767        /**
    78          * Keep the previous and next post links inside the language of the post being viewed.
    79          *
    8068         * @param mixed $where    WHERE clause of the adjacent post query; the posts table is aliased p.
    8169         * @param mixed $same     Unused.
    … …  
    10391                        return $default ? $where : $where . ' AND 1 = 0';
    10492                }
    105                 // $ids holds integers only, read from the language terms above.
     93
    10694                return $where . ' AND p.ID ' . ( $default ? 'NOT IN' : 'IN' ) . " ( SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN ( " . implode( ',', $ids ) . ' ) )';
    10795        }
  • vabelon/tags/26.11.27.19/src/Routing/Request.php

    r3826639 r3830701  
    1414defined( 'ABSPATH' ) || exit;
    1515
    16 /**
    17  * Request language.
    18  */
     16
    1917final class Request {
    2018
    21         /**
    22          * Language resolved for this request.
    23          *
    24          * @var string|null
    25          */
     19        /** @var string|null */
    2620        private ?string $resolved = null;
    2721
    28         /**
    29          * Address prefix of the language this request is for.
    30          *
    31          * @return string
    32          */
     22        /** @return string */
    3323        public function language(): string {
    3424                if ( ! $this->is_public() ) {
    … …  
    4333
    4434        /**
    45          * The language an address belongs to.
    46          *
    4735         * @param string $uri Request address, path first.
    4836         * @return string
    … …  
    5240        }
    5341
    54         /**
    55          * Whether this is a visitor-facing page request.
    56          *
    57          * @return bool
    58          */
     42        /** @return bool */
    5943        public function is_public(): bool {
    6044                global $pagenow;
    … …  
    6953        }
    7054
    71         /**
    72          * The site's home address as stored, without a trailing slash.
    73          *
    74          * @return string
    75          */
     55        /** @return string */
    7656        public static function home(): string {
    7757                $home = get_option( 'home', '' );
  • vabelon/tags/26.11.27.19/src/Routing/Rewrites.php

    r3827447 r3830701  
    1414defined( 'ABSPATH' ) || exit;
    1515
    16 /**
    17  * Rewrite rules.
    18  */
     16
    1917final class Rewrites {
    2018
    2119        private const FAMILIES = array( 'post', 'page', 'date', 'author', 'search', 'root', 'category', 'post_tag' );
    2220
    23         /**
    24          * Hook the rules into WordPress.
    25          *
    26          * @return void
    27          */
     21        /** @return void */
    2822        public function register(): void {
    2923                add_filter( 'query_vars', array( $this, 'query_vars' ) );
    … …  
    3832
    3933        /**
    40          * Allow the language in the query.
    41          *
    4234         * @param array<int,string> $vars Public query variables.
    4335         * @return array<int,string>
    … …  
    4941
    5042        /**
    51          * Add a copy of each rule that starts with a language prefix.
    52          *
    5343         * @param array<string,string> $rules Rules of one family.
    5444         * @return array<string,string>
    … …  
    7969        }
    8070
    81         /**
    82          * Add the rule for each language's home address.
    83          *
    84          * @return void
    85          */
     71        /** @return void */
    8672        public function add_home_rule(): void {
    8773                $group = $this->language_group();
    … …  
    9177        }
    9278
    93         /**
    94          * Rebuild WordPress's rules when the languages or the address structure changed.
    95          *
    96          * @return void
    97          */
     79        /** @return void */
    9880        public function maybe_flush(): void {
    9981                $signature = hash( 'sha256', (string) wp_json_encode( array( VABELON_VERSION, Plugin::languages()->all(), get_option( 'permalink_structure', '' ) ) ) );
    … …  
    10688
    10789        /**
    108          * Stop WordPress redirecting a language address to another language.
    109          *
    11090         * @param mixed $redirect  Address WordPress wants to redirect to.
    11191         * @param mixed $requested Address that was requested.
    … …  
    123103        }
    124104
    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 */
    130106        public function home_slash(): void {
    131107                $method   = isset( $_SERVER['REQUEST_METHOD'] ) && is_string( $_SERVER['REQUEST_METHOD'] ) ? sanitize_key( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) : '';
    … …  
    147123        }
    148124
    149         /**
    150          * Regex group matching every language prefix except the default, followed by a slash.
    151          *
    152          * @return string
    153          */
     125        /** @return string */
    154126        private function language_group(): string {
    155127                $slugs = Plugin::languages()->non_default_slugs();
  • vabelon/tags/26.11.27.19/src/Routing/StaticPages.php

    r3827447 r3830701  
    1515defined( 'ABSPATH' ) || exit;
    1616
    17 /**
    18  * Static front page and posts page per language.
    19  */
     17
    2018final class StaticPages {
    2119
    22         /**
    23          * Whether the front page option is being read unfiltered.
    24          *
    25          * @var bool
    26          */
     20        /** @var bool */
    2721        private static bool $reading_original = false;
    2822
    29         /**
    30          * Hook into WordPress.
    31          *
    32          * @return void
    33          */
     23        /** @return void */
    3424        public function register(): void {
    3525                add_filter( 'option_page_on_front', array( $this, 'front_page_id' ) );
    … …  
    3929        }
    4030
    41         /**
    42          * The front page chosen in Settings > Reading, in the default language.
    43          *
    44          * @return int
    45          */
     31        /** @return int */
    4632        public static function original_front(): int {
    4733                self::$reading_original = true;
    … …  
    5238
    5339        /**
    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          *
    5840         * @param mixed $value Stored page ID.
    5941         * @return mixed
    … …  
    7254
    7355        /**
    74          * Turn a language home request into a request for that language's front page.
    75          *
    7656         * @param WP_Query $query Query about to run.
    7757         * @return void
    … …  
    10181        }
    10282
    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 */
    10884        public function redirect_to_language(): void {
    10985                if ( ! is_singular() || is_preview() ) {
  • vabelon/tags/26.11.27.19/src/Routing/Urls.php

    r3827447 r3830701  
    1414defined( 'ABSPATH' ) || exit;
    1515
    16 /**
    17  * Language addresses.
    18  */
     16
    1917final class Urls {
    2018
    2119        /**
    22          * Home address of a language.
    23          *
    2420         * @param string $slug Language address prefix.
    2521         * @return string
    … …  
    3026
    3127        /**
    32          * Whether a post is the front page or one of its translations.
    33          *
    3428         * @param int $post_id Post ID.
    3529         * @return bool
    … …  
    4438
    4539        /**
    46          * Put an address into a language.
    47          *
    4840         * @param string $url  Address on this site.
    4941         * @param string $slug Language address prefix.
    … …  
    7668
    7769        /**
    78          * The language an address belongs to.
    79          *
    8070         * @param string $url Address.
    8171         * @return string
    … …  
    8979
    9080        /**
    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, where
    94          * user_trailingslashit() cannot be called.
    95          *
    9681         * @param string $path Path without a trailing slash.
    9782         * @return string
    … …  
    10691
    10792        /**
    108          * A path relative to the home path, with any language prefix removed.
    109          *
    11093         * @param string $path  Path of an address.
    11194         * @param string $base  Path of the home address.
    … …  
    130113
    131114        /**
    132          * Whether a parsed address is on this site.
    133          *
    134115         * @param array<string,int|string> $parts Parsed address.
    135116         * @return bool
  • vabelon/tags/26.11.27.19/vabelon.php

    r3827447 r3830701  
    33 * Plugin Name:       Vabelon: Lightweight Multilingual, Hreflang Tags & Language Switcher
    44 * Description:       Multilingual WordPress in a small plugin: languages, translated addresses, hreflang and a language switcher.
    5  * Version:           26.11.26.10
     5 * Version:           26.11.27.19
    66 * Requires at least: 6.2
    77 * Requires PHP:      7.4
    … …  
    2020defined( 'ABSPATH' ) || exit;
    2121
    22 define( 'VABELON_VERSION', '26.11.26.10' );
     22define( 'VABELON_VERSION', '26.11.27.19' );
    2323define( 'VABELON_FILE', __FILE__ );
    2424define( 'VABELON_PATH', plugin_dir_path( __FILE__ ) );
    … …  
    4040add_action( 'plugins_loaded', array( \Vabelon\Plugin::class, 'boot' ) );
    4141
    42 /**
    43  * Print the language switcher. For use in theme templates.
    44  *
    45  * @return void
    46  */
     42/** @return void */
    4743function vabelon_switcher(): void {
    4844        do_action( 'vabelon_switcher' );
    4945}
    5046
    51 /**
    52  * Address prefix of the language the current request is for.
    53  *
    54  * @return string
    55  */
     47/** @return string */
    5648function vabelon_current_language(): string {
    5749        return \Vabelon\Plugin::request()->language();
    5850}
    5951
    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>> */
    6553function vabelon_languages(): array {
    6654        return array_values( array_map( 'get_object_vars', \Vabelon\Plugin::languages()->all() ) );
    … …  
    6856
    6957/**
    70  * The language a post was given, or null when it has none and is shown as the default language.
    71  *
    7258 * @param int $post_id Post ID.
    7359 * @return string|null
    … …  
    7864
    7965/**
    80  * A post and its translations, as language address prefix => post ID.
    81  *
    8266 * @param int               $post_id  Post ID.
    8367 * @param array<int,string> $statuses Keep only posts with one of these statuses; empty keeps all.
  • vabelon/trunk/languages/vabelon.pot

    r3827447 r3830701  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Vabelon: Lightweight Multilingual, Hreflang Tags & Language Switcher 26.11.26.10\n"
     5"Project-Id-Version: Vabelon: Lightweight Multilingual, Hreflang Tags & Language Switcher 26.11.27.19\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/vabelon\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
  • vabelon/trunk/readme.txt

    r3827588 r3830701  
    55Tested up to: 7.1
    66Requires PHP: 7.4
    7 Stable tag: 26.11.26.10
     7Stable tag: 26.11.27.19
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    110110[View the complete release history](https://vabelon.com/changelog).
    111111
     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
    112116= 26.11.26.10 =
    113117
  • vabelon/trunk/src/Admin/Settings.php

    r3827447 r3830701  
    1616defined( 'ABSPATH' ) || exit;
    1717
    18 /**
    19  * Settings page, built on the WordPress Settings API.
    20  */
     18
    2119final class Settings {
    2220
    … …  
    2422        public const GROUP = 'vabelon';
    2523
    26         /**
    27          * Hook the page into WordPress.
    28          *
    29          * @return void
    30          */
     24        /** @return void */
    3125        public function register(): void {
    3226                add_action( 'admin_menu', array( $this, 'menu' ) );
    … …  
    3630
    3731        /**
    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          *
    4232         * @param mixed $plugins Plugins keyed by basename.
    4333         * @return mixed
    … …  
    5141        }
    5242
    53         /**
    54          * Add the page under Settings.
    55          *
    56          * @return void
    57          */
     43        /** @return void */
    5844        public function menu(): void {
    5945                add_options_page( 'Vabelon', 'Vabelon', 'manage_options', self::PAGE, array( $this, 'render' ) );
    6046        }
    6147
    62         /**
    63          * Register the option with the Settings API.
    64          *
    65          * @return void
    66          */
     48        /** @return void */
    6749        public function setting(): void {
    6850                register_setting(
    … …  
    8769
    8870        /**
    89          * Keep only menu choices for a configured language, a theme location and a menu that exists.
    90          *
    9171         * @param mixed $input Submitted choices: language => location => menu ID.
    9272         * @return array<string,array<string,int>>
    … …  
    11292        }
    11393
    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 */
    12195        private function menus_table(): void {
    12296                $locations = get_registered_nav_menus();
    … …  
    149123
    150124        /**
    151          * Validate and sanitize the value before it is stored.
    152          *
    153          * Accepts the settings form (rows and default) or the stored shape (items), which
    154          * Languages::save() passes through update_option(). Both are validated the same way.
    155          *
    156125         * @param mixed $input Submitted form or stored shape.
    157126         * @return mixed The value to store.
    … …  
    175144
    176145        /**
    177          * Language rows from the settings form: removed and empty rows are dropped, and
    178          * the chosen radio button marks the default.
    179          *
    180146         * @param array $input Submitted form.
    181147         * @return array<int,array>
    … …  
    198164        }
    199165
    200         /**
    201          * Print the page.
    202          *
    203          * @return void
    204          */
     166        /** @return void */
    205167        public function render(): void {
    206168                if ( ! current_user_can( 'manage_options' ) ) {
    … …  
    232194                        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>';
    233195                        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>';
    235197                        }
    236198                        echo '<td>';
  • vabelon/trunk/src/Admin/TranslationsBox.php

    r3826639 r3830701  
    1616defined( 'ABSPATH' ) || exit;
    1717
    18 /**
    19  * Editor meta box.
    20  */
     18
    2119final class TranslationsBox {
    2220
    23         /**
    24          * Hook the box into WordPress.
    25          *
    26          * @return void
    27          */
     21        /** @return void */
    2822        public function register(): void {
    2923                add_action( 'add_meta_boxes', array( $this, 'add' ) );
    … …  
    3226        }
    3327
    34         /**
    35          * Add the box to every supported post type.
    36          *
    37          * @return void
    38          */
     28        /** @return void */
    3929        public function add(): void {
    4030                foreach ( Plugin::translations()->post_types() as $type ) {
    … …  
    4434
    4535        /**
    46          * Print the box.
    47          *
    4836         * @param WP_Post $post Post being edited.
    4937         * @return void
    … …  
    7563
    7664        /**
    77          * Save the box.
    78          *
    7965         * @param int     $post_id Post ID.
    8066         * @param WP_Post $post    Post being saved.
    … …  
    10389
    10490        /**
    105          * Apply the box's choices to a post.
    106          *
    10791         * @param int               $post_id  Post ID.
    10892         * @param string            $language Chosen language.
    … …  
    137121        }
    138122
    139         /**
    140          * Show the last error once.
    141          *
    142          * @return void
    143          */
     123        /** @return void */
    144124        public function notice(): void {
    145125                $key     = 'vabelon_box_error_' . get_current_user_id();
  • vabelon/trunk/src/Content/Translations.php

    r3826639 r3830701  
    1818defined( 'ABSPATH' ) || exit;
    1919
    20 /**
    21  * Reads and writes the two taxonomies.
    22  */
     20
    2321final class Translations {
    2422
    … …  
    2624        public const GROUP    = 'vabelon_group';
    2725
    28         /**
    29          * Hook the taxonomies into WordPress.
    30          *
    31          * @return void
    32          */
     26        /** @return void */
    3327        public function register(): void {
    3428                add_action( 'init', array( $this, 'register_taxonomies' ), 5 );
    3529        }
    3630
    37         /**
    38          * Register both hidden taxonomies.
    39          *
    40          * @return void
    41          */
     31        /** @return void */
    4232        public function register_taxonomies(): void {
    4333                foreach ( array( self::LANGUAGE, self::GROUP ) as $taxonomy ) {
    … …  
    5444        }
    5545
    56         /**
    57          * Post types that can have a language.
    58          *
    59          * @return array<int,string>
    60          */
     46        /** @return array<int,string> */
    6147        public function post_types(): array {
    6248                $types = apply_filters( 'vabelon_post_types', array( 'post', 'page' ) );
    … …  
    6652
    6753        /**
    68          * Whether a post can have a language.
    69          *
    7054         * @param int $post_id Post ID.
    7155         * @return bool
    … …  
    7761
    7862        /**
    79          * The language a post was given, or null.
    80          *
    8163         * @param int $post_id Post ID.
    8264         * @return string|null
    … …  
    8870
    8971        /**
    90          * The language a post is shown in: its own, or the default.
    91          *
    9272         * @param int $post_id Post ID.
    9373         * @return string
    … …  
    9979
    10080        /**
    101          * Give a post a language.
    102          *
    10381         * @param int    $post_id Post ID.
    10482         * @param string $slug    Language address prefix.
    … …  
    11492
    11593        /**
    116          * The translation group of a post, or null.
    117          *
    11894         * @param int $post_id Post ID.
    11995         * @return string|null
    … …  
    124100
    125101        /**
    126          * A post and its translations, as language => post ID.
    127          *
    128102         * @param int               $post_id  Post ID.
    129103         * @param array<int,string> $statuses Keep only posts with one of these statuses; empty keeps all.
    … …  
    152126
    153127        /**
    154          * Link a post as the translation of another, in a language.
    155          *
    156128         * @param int    $source   Post that already exists in its language.
    157129         * @param int    $target   Post that becomes the translation.
    … …  
    195167
    196168        /**
    197          * Take a post out of its translation group.
    198          *
    199169         * @param int $post_id Post ID.
    200170         * @return bool Whether the post was in a group.
    … …  
    221191
    222192        /**
    223          * Slug of the first term a post has in a taxonomy, or null.
    224          *
    225193         * @param int    $post_id  Post ID.
    226194         * @param string $taxonomy Taxonomy name.
  • vabelon/trunk/src/Frontend/ContentLinks.php

    r3827447 r3830701  
    1414defined( 'ABSPATH' ) || exit;
    1515
    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
    2217final class ContentLinks {
    2318
    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> */
    2920        private array $seen = array();
    3021
    31         /**
    32          * Hook into WordPress.
    33          *
    34          * @return void
    35          */
     22        /** @return void */
    3623        public function register(): void {
    3724                add_filter( 'the_content', array( $this, 'localize' ), 20 );
    … …  
    3926
    4027        /**
    41          * Point the links of a translated page at translations.
    42          *
    4328         * @param mixed $content Post content.
    4429         * @return mixed
    … …  
    6449
    6550        /**
    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 published
    69          * translation. A link to a page nobody translated keeps working in the other language.
    70          *
    7151         * @param string $href     Address as written.
    7252         * @param string $language Language address prefix.
    … …  
    8262                $key = $language . ' ' . $path;
    8363                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
    8565                        add_filter( 'vabelon_request_is_public', '__return_false', 99 );
    8666                        $post_id = url_to_postid( $path );
  • vabelon/trunk/src/Frontend/Hreflang.php

    r3827447 r3830701  
    1515defined( 'ABSPATH' ) || exit;
    1616
    17 /**
    18  * Hreflang links.
    19  */
     17
    2018final class Hreflang {
    2119
    22         /**
    23          * Hook into WordPress.
    24          *
    25          * @return void
    26          */
     20        /** @return void */
    2721        public function register(): void {
    2822                add_action( 'wp_head', array( $this, 'output' ), 2 );
    … …  
    3024
    3125        /**
    32          * Alternates of a post: one row per published translation, plus x-default.
    33          *
    3426         * @param int $post_id Post ID.
    3527         * @return array<int,array{hreflang:string,href:string}>
    … …  
    4436        }
    4537
    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}> */
    5139        public function home_model(): array {
    5240                if ( 'page' === get_option( 'show_on_front' ) ) {
    … …  
    6250
    6351        /**
    64          * The link elements for a list of alternates.
    65          *
    6652         * @param array<int,array{hreflang:string,href:string}> $model Alternates.
    6753         * @return string
    … …  
    7561        }
    7662
    77         /**
    78          * Print the alternates of the current page.
    79          *
    80          * @return void
    81          */
     63        /** @return void */
    8264        public function output(): void {
    8365                if ( is_404() || is_preview() || is_search() || is_archive() || is_paged() ) {
    … …  
    8668                $model = array();
    8769                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
    8971                        $model = $this->singular_model( get_queried_object_id() );
    9072                } elseif ( is_front_page() ) {
    … …  
    9577
    9678        /**
    97          * Rows in language order, with x-default pointing at the default language.
    98          *
    9979         * @param array<string,string> $addresses Language address prefix => address.
    10080         * @return array<int,array{hreflang:string,href:string}>
  • vabelon/trunk/src/Frontend/Locale.php

    r3826639 r3830701  
    1414defined( 'ABSPATH' ) || exit;
    1515
    16 /**
    17  * Locale per language.
    18  */
     16
    1917final class Locale {
    2018
    21         /**
    22          * Whether the locale is being resolved right now.
    23          *
    24          * @var bool
    25          */
     19        /** @var bool */
    2620        private bool $resolving = false;
    2721
    28         /**
    29          * Hook into WordPress.
    30          *
    31          * @return void
    32          */
     22        /** @return void */
    3323        public function register(): void {
    3424                add_filter( 'determine_locale', array( $this, 'filter' ), 20 );
    … …  
    3727
    3828        /**
    39          * The locale of the request's language.
    40          *
    4129         * @param mixed $locale Locale WordPress chose.
    4230         * @return mixed
  • vabelon/trunk/src/Frontend/Menus.php

    r3827447 r3830701  
    1414defined( 'ABSPATH' ) || exit;
    1515
    16 /**
    17  * Navigation menus.
    18  */
     16
    1917final class Menus {
    2018
    2119        public const OPTION = 'vabelon_menu_locations';
    2220
    23         /**
    24          * Hook into WordPress.
    25          *
    26          * @return void
    27          */
     21        /** @return void */
    2822        public function register(): void {
    2923                add_filter( 'theme_mod_nav_menu_locations', array( $this, 'filter_locations' ) );
    … …  
    3125        }
    3226
    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>> */
    3828        public static function map(): array {
    3929                $stored = get_option( self::OPTION, array() );
    … …  
    5040
    5141        /**
    52          * Menu locations for the language of the request.
    53          *
    5442         * @param mixed $locations Theme location => menu ID.
    5543         * @return mixed
    … …  
    6048
    6149        /**
    62          * Menu locations for a language.
    63          *
    64          * A language with no menus of its own uses the default language's. Once a language has
    65          * a menu, a location it leaves empty shows no menu on its pages.
    66          *
    6750         * @param array<mixed> $locations Theme location => menu ID.
    6851         * @param string       $language  Language address prefix.
    … …  
    9073
    9174        /**
    92          * Menu items for the language of the request.
    93          *
    9475         * @param mixed $items Menu items.
    9576         * @return mixed
    … …  
    10081
    10182        /**
    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          *
    10683         * @param array<int|string,mixed> $items    Menu items.
    10784         * @param string                  $language Language address prefix.
  • vabelon/trunk/src/Frontend/Switcher.php

    r3827447 r3830701  
    1515defined( 'ABSPATH' ) || exit;
    1616
    17 /**
    18  * Language switcher.
    19  */
     17
    2018final class Switcher {
    2119
    … …  
    3634        );
    3735
    38         /**
    39          * Hook into WordPress.
    40          *
    41          * @return void
    42          */
     36        /** @return void */
    4337        public function register(): void {
    4438                add_shortcode( 'vabelon_switcher', array( $this, 'shortcode' ) );
    … …  
    4741
    4842        /**
    49          * The links to show.
    50          *
    5143         * @param int|null $post_id Post being viewed, or null on a page that is not one post.
    5244         * @param string   $active  Language of the page being viewed.
    … …  
    7365
    7466        /**
    75          * The switcher's markup; empty when there is nothing to switch to.
    76          *
    7767         * @param array<int,array{slug:string,label:string,hreflang:string,url:string,is_current:bool}> $items Links.
    7868         * @return string
    … …  
    9686        }
    9787
    98         /**
    99          * The switcher for the page being viewed.
    100          *
    101          * @return string
    102          */
     88        /** @return string */
    10389        public function shortcode(): string {
    10490                $post_id = is_singular() || ( is_home() && ! is_front_page() ) ? get_queried_object_id() : 0;
    … …  
    10894        }
    10995
    110         /**
    111          * Print the switcher for the page being viewed.
    112          *
    113          * @return void
    114          */
     96        /** @return void */
    11597        public function output(): void {
    11698                echo wp_kses( $this->shortcode(), self::ALLOWED );
  • vabelon/trunk/src/Language/Language.php

    r3826639 r3830701  
    1212defined( 'ABSPATH' ) || exit;
    1313
    14 /**
    15  * Description of a language. Built by Languages from validated rows.
    16  */
     14
    1715final class Language {
    1816
    19         /**
    20          * Address prefix, such as "es".
    21          *
    22          * @var string
    23          */
     17        /** @var string */
    2418        public string $slug;
    2519
    26         /**
    27          * WordPress locale, such as "es_ES".
    28          *
    29          * @var string
    30          */
     20        /** @var string */
    3121        public string $wp_locale;
    3222
    33         /**
    34          * Value for hreflang attributes, such as "es".
    35          *
    36          * @var string
    37          */
     23        /** @var string */
    3824        public string $hreflang;
    3925
    40         /**
    41          * Name in the site's language.
    42          *
    43          * @var string
    44          */
     26        /** @var string */
    4527        public string $name;
    4628
    47         /**
    48          * Name in the language itself.
    49          *
    50          * @var string
    51          */
     29        /** @var string */
    5230        public string $native_name;
    5331
    54         /**
    55          * Whether this is the site's default language.
    56          *
    57          * @var bool
    58          */
     32        /** @var bool */
    5933        public bool $is_default;
    6034
    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. */
    6636        public function __construct( array $row ) {
    6737                $this->slug        = $row['slug'];
  • vabelon/trunk/src/Language/Languages.php

    r3826639 r3830701  
    1414defined( 'ABSPATH' ) || exit;
    1515
    16 /**
    17  * Language registry.
    18  */
     16
    1917final class Languages {
    2018
    … …  
    2321        private const RESERVED = array( 'wp-admin', 'wp-json', 'wp-content', 'wp-includes', 'feed', 'page', 'author', 'category', 'tag', 'search', 'comments', 'embed' );
    2422
    25         /**
    26          * Languages read during this request.
    27          *
    28          * @var array<int,Language>|null
    29          */
     23        /** @var array<int,Language>|null */
    3024        private ?array $cache = null;
    3125
    32         /**
    33          * Fingerprint of the stored option the cache was built from.
    34          *
    35          * @var string
    36          */
     26        /** @var string */
    3727        private string $cache_key = '';
    3828
    39         /**
    40          * Every configured language, in stored order.
    41          *
    42          * @return array<int,Language>
    43          */
     29        /** @return array<int,Language> */
    4430        public function all(): array {
    4531                $stored = get_option( self::OPTION, array() );
    … …  
    6046
    6147        /**
    62          * One language by its address prefix.
    63          *
    6448         * @param string $slug Address prefix.
    6549         * @return Language|null
    … …  
    7458        }
    7559
    76         /**
    77          * Address prefix of the default language, or '' when none is configured.
    78          *
    79          * @return string
    80          */
     60        /** @return string */
    8161        public function default_slug(): string {
    8262                foreach ( $this->all() as $language ) {
    … …  
    8868        }
    8969
    90         /**
    91          * Address prefixes of every language except the default.
    92          *
    93          * @return array<int,string>
    94          */
     70        /** @return array<int,string> */
    9571        public function non_default_slugs(): array {
    9672                $slugs = array();
    … …  
    10480
    10581        /**
    106          * Check and normalize a list of language rows. Writes nothing.
    107          *
    10882         * @param array $rows Rows with slug, wp_locale, hreflang, name, native_name and is_default.
    10983         * @return array<int,array{slug:string,wp_locale:string,hreflang:string,name:string,native_name:string,is_default:bool}>|WP_Error
    … …  
    145119
    146120        /**
    147          * Save a list of language rows.
    148          *
    149121         * @param array $rows Rows as accepted by validate().
    150122         * @return true|WP_Error
    … …  
    167139        }
    168140
    169         /**
    170          * On first activation, make the site's own language the default.
    171          *
    172          * @return void
    173          */
     141        /** @return void */
    174142        public function seed_from_site_locale(): void {
    175143                if ( false !== get_option( self::OPTION, false ) ) {
    … …  
    193161
    194162        /**
    195          * Name of the first field of a row that is not valid, or ''.
    196          *
    197163         * @param array{slug:string,wp_locale:string,hreflang:string,name:string,native_name:string,is_default:bool} $item Row.
    198164         * @return string
    … …  
    217183
    218184        /**
    219          * A string from a scalar value; '' for anything else.
    220          *
    221185         * @param mixed $value Value.
    222186         * @return string
  • vabelon/trunk/src/Plugin.php

    r3827447 r3830701  
    1717defined( 'ABSPATH' ) || exit;
    1818
    19 /**
    20  * Plugin bootstrap and the four objects every component shares.
    21  */
     19
    2220final class Plugin {
    2321
    24         /**
    25          * Shared objects, created on first use.
    26          *
    27          * @var array<string,object>
    28          */
     22        /** @var array<string,object> */
    2923        private static array $shared = array();
    3024
    31         /**
    32          * Register every component once.
    33          *
    34          * @return void
    35          */
     25        /** @return void */
    3626        public static function boot(): void {
    3727                if ( isset( self::$shared['booted'] ) ) {
    … …  
    5747        }
    5848
    59         /**
    60          * The language registry.
    61          *
    62          * @return Languages
    63          */
     49        /** @return Languages */
    6450        public static function languages(): Languages {
    6551                $found = self::$shared['languages'] ?? null;
    … …  
    7157        }
    7258
    73         /**
    74          * The translation storage.
    75          *
    76          * @return Translations
    77          */
     59        /** @return Translations */
    7860        public static function translations(): Translations {
    7961                $found = self::$shared['translations'] ?? null;
    … …  
    8567        }
    8668
    87         /**
    88          * The language addresses.
    89          *
    90          * @return Urls
    91          */
     69        /** @return Urls */
    9270        public static function urls(): Urls {
    9371                $found = self::$shared['urls'] ?? null;
    … …  
    9977        }
    10078
    101         /**
    102          * The request language.
    103          *
    104          * @return Request
    105          */
     79        /** @return Request */
    10680        public static function request(): Request {
    10781                $found = self::$shared['request'] ?? null;
    … …  
    11387        }
    11488
    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 */
    12090        public static function activate(): void {
    12191                self::languages()->seed_from_site_locale();
    … …  
    12393        }
    12494
    125         /**
    126          * Deactivation: let WordPress rebuild its rules without the language routes.
    127          *
    128          * @return void
    129          */
     95        /** @return void */
    13096        public static function deactivate(): void {
    13197                delete_option( 'vabelon_rewrite_signature' );
  • vabelon/trunk/src/Routing/Permalinks.php

    r3826639 r3830701  
    1515defined( 'ABSPATH' ) || exit;
    1616
    17 /**
    18  * Permalink filters.
    19  */
     17
    2018final class Permalinks {
    2119
    2220        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' );
    2321
    24         /**
    25          * Whether home_url() is being filtered right now.
    26          *
    27          * @var bool
    28          */
     22        /** @var bool */
    2923        private bool $filtering_home = false;
    3024
    31         /**
    32          * Hook the filters into WordPress.
    33          *
    34          * @return void
    35          */
     25        /** @return void */
    3626        public function register(): void {
    3727                foreach ( array( 'post_link', 'page_link', 'post_type_link' ) as $filter ) {
    … …  
    4535
    4636        /**
    47          * Address of a post, in the post's own language.
    48          *
    4937         * @param mixed $url  Address WordPress built.
    5038         * @param mixed $post Post object or ID.
    … …  
    6149
    6250        /**
    63          * Address of an archive, search or feed, in the language of the request.
    64          *
    6551         * @param mixed $url Address WordPress built.
    6652         * @return mixed
    … …  
    7460
    7561        /**
    76          * The home address, in the language of the request.
    77          *
    7862         * @param mixed $url  Address WordPress built.
    7963         * @param mixed $path Path that was asked for.
  • vabelon/trunk/src/Routing/QueryLanguage.php

    r3827447 r3830701  
    1818defined( 'ABSPATH' ) || exit;
    1919
    20 /**
    21  * Query scoping.
    22  */
     20
    2321final class QueryLanguage {
    2422
    25         /**
    26          * Hook the scoping into WordPress.
    27          *
    28          * @return void
    29          */
     23        /** @return void */
    3024        public function register(): void {
    3125                add_action( 'pre_get_posts', array( $this, 'scope' ), 1 );
    … …  
    3529
    3630        /**
    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          *
    4131         * @param WP_Query $query Query about to run.
    4232         * @return void
    … …  
    4737                        return;
    4838                }
    49                 // WordPress leaves the post type empty on the blog index, search, feeds and most archives.
     39
    5040                $types = array_filter(
    5141                        (array) $query->get( 'post_type' ),
    … …  
    7666
    7767        /**
    78          * Keep the previous and next post links inside the language of the post being viewed.
    79          *
    8068         * @param mixed $where    WHERE clause of the adjacent post query; the posts table is aliased p.
    8169         * @param mixed $same     Unused.
    … …  
    10391                        return $default ? $where : $where . ' AND 1 = 0';
    10492                }
    105                 // $ids holds integers only, read from the language terms above.
     93
    10694                return $where . ' AND p.ID ' . ( $default ? 'NOT IN' : 'IN' ) . " ( SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN ( " . implode( ',', $ids ) . ' ) )';
    10795        }
  • vabelon/trunk/src/Routing/Request.php

    r3826639 r3830701  
    1414defined( 'ABSPATH' ) || exit;
    1515
    16 /**
    17  * Request language.
    18  */
     16
    1917final class Request {
    2018
    21         /**
    22          * Language resolved for this request.
    23          *
    24          * @var string|null
    25          */
     19        /** @var string|null */
    2620        private ?string $resolved = null;
    2721
    28         /**
    29          * Address prefix of the language this request is for.
    30          *
    31          * @return string
    32          */
     22        /** @return string */
    3323        public function language(): string {
    3424                if ( ! $this->is_public() ) {
    … …  
    4333
    4434        /**
    45          * The language an address belongs to.
    46          *
    4735         * @param string $uri Request address, path first.
    4836         * @return string
    … …  
    5240        }
    5341
    54         /**
    55          * Whether this is a visitor-facing page request.
    56          *
    57          * @return bool
    58          */
     42        /** @return bool */
    5943        public function is_public(): bool {
    6044                global $pagenow;
    … …  
    6953        }
    7054
    71         /**
    72          * The site's home address as stored, without a trailing slash.
    73          *
    74          * @return string
    75          */
     55        /** @return string */
    7656        public static function home(): string {
    7757                $home = get_option( 'home', '' );
  • vabelon/trunk/src/Routing/Rewrites.php

    r3827447 r3830701  
    1414defined( 'ABSPATH' ) || exit;
    1515
    16 /**
    17  * Rewrite rules.
    18  */
     16
    1917final class Rewrites {
    2018
    2119        private const FAMILIES = array( 'post', 'page', 'date', 'author', 'search', 'root', 'category', 'post_tag' );
    2220
    23         /**
    24          * Hook the rules into WordPress.
    25          *
    26          * @return void
    27          */
     21        /** @return void */
    2822        public function register(): void {
    2923                add_filter( 'query_vars', array( $this, 'query_vars' ) );
    … …  
    3832
    3933        /**
    40          * Allow the language in the query.
    41          *
    4234         * @param array<int,string> $vars Public query variables.
    4335         * @return array<int,string>
    … …  
    4941
    5042        /**
    51          * Add a copy of each rule that starts with a language prefix.
    52          *
    5343         * @param array<string,string> $rules Rules of one family.
    5444         * @return array<string,string>
    … …  
    7969        }
    8070
    81         /**
    82          * Add the rule for each language's home address.
    83          *
    84          * @return void
    85          */
     71        /** @return void */
    8672        public function add_home_rule(): void {
    8773                $group = $this->language_group();
    … …  
    9177        }
    9278
    93         /**
    94          * Rebuild WordPress's rules when the languages or the address structure changed.
    95          *
    96          * @return void
    97          */
     79        /** @return void */
    9880        public function maybe_flush(): void {
    9981                $signature = hash( 'sha256', (string) wp_json_encode( array( VABELON_VERSION, Plugin::languages()->all(), get_option( 'permalink_structure', '' ) ) ) );
    … …  
    10688
    10789        /**
    108          * Stop WordPress redirecting a language address to another language.
    109          *
    11090         * @param mixed $redirect  Address WordPress wants to redirect to.
    11191         * @param mixed $requested Address that was requested.
    … …  
    123103        }
    124104
    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 */
    130106        public function home_slash(): void {
    131107                $method   = isset( $_SERVER['REQUEST_METHOD'] ) && is_string( $_SERVER['REQUEST_METHOD'] ) ? sanitize_key( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) : '';
    … …  
    147123        }
    148124
    149         /**
    150          * Regex group matching every language prefix except the default, followed by a slash.
    151          *
    152          * @return string
    153          */
     125        /** @return string */
    154126        private function language_group(): string {
    155127                $slugs = Plugin::languages()->non_default_slugs();
  • vabelon/trunk/src/Routing/StaticPages.php

    r3827447 r3830701  
    1515defined( 'ABSPATH' ) || exit;
    1616
    17 /**
    18  * Static front page and posts page per language.
    19  */
     17
    2018final class StaticPages {
    2119
    22         /**
    23          * Whether the front page option is being read unfiltered.
    24          *
    25          * @var bool
    26          */
     20        /** @var bool */
    2721        private static bool $reading_original = false;
    2822
    29         /**
    30          * Hook into WordPress.
    31          *
    32          * @return void
    33          */
     23        /** @return void */
    3424        public function register(): void {
    3525                add_filter( 'option_page_on_front', array( $this, 'front_page_id' ) );
    … …  
    3929        }
    4030
    41         /**
    42          * The front page chosen in Settings > Reading, in the default language.
    43          *
    44          * @return int
    45          */
     31        /** @return int */
    4632        public static function original_front(): int {
    4733                self::$reading_original = true;
    … …  
    5238
    5339        /**
    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          *
    5840         * @param mixed $value Stored page ID.
    5941         * @return mixed
    … …  
    7254
    7355        /**
    74          * Turn a language home request into a request for that language's front page.
    75          *
    7656         * @param WP_Query $query Query about to run.
    7757         * @return void
    … …  
    10181        }
    10282
    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 */
    10884        public function redirect_to_language(): void {
    10985                if ( ! is_singular() || is_preview() ) {
  • vabelon/trunk/src/Routing/Urls.php

    r3827447 r3830701  
    1414defined( 'ABSPATH' ) || exit;
    1515
    16 /**
    17  * Language addresses.
    18  */
     16
    1917final class Urls {
    2018
    2119        /**
    22          * Home address of a language.
    23          *
    2420         * @param string $slug Language address prefix.
    2521         * @return string
    … …  
    3026
    3127        /**
    32          * Whether a post is the front page or one of its translations.
    33          *
    3428         * @param int $post_id Post ID.
    3529         * @return bool
    … …  
    4438
    4539        /**
    46          * Put an address into a language.
    47          *
    4840         * @param string $url  Address on this site.
    4941         * @param string $slug Language address prefix.
    … …  
    7668
    7769        /**
    78          * The language an address belongs to.
    79          *
    8070         * @param string $url Address.
    8171         * @return string
    … …  
    8979
    9080        /**
    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, where
    94          * user_trailingslashit() cannot be called.
    95          *
    9681         * @param string $path Path without a trailing slash.
    9782         * @return string
    … …  
    10691
    10792        /**
    108          * A path relative to the home path, with any language prefix removed.
    109          *
    11093         * @param string $path  Path of an address.
    11194         * @param string $base  Path of the home address.
    … …  
    130113
    131114        /**
    132          * Whether a parsed address is on this site.
    133          *
    134115         * @param array<string,int|string> $parts Parsed address.
    135116         * @return bool
  • vabelon/trunk/vabelon.php

    r3827447 r3830701  
    33 * Plugin Name:       Vabelon: Lightweight Multilingual, Hreflang Tags & Language Switcher
    44 * Description:       Multilingual WordPress in a small plugin: languages, translated addresses, hreflang and a language switcher.
    5  * Version:           26.11.26.10
     5 * Version:           26.11.27.19
    66 * Requires at least: 6.2
    77 * Requires PHP:      7.4
    … …  
    2020defined( 'ABSPATH' ) || exit;
    2121
    22 define( 'VABELON_VERSION', '26.11.26.10' );
     22define( 'VABELON_VERSION', '26.11.27.19' );
    2323define( 'VABELON_FILE', __FILE__ );
    2424define( 'VABELON_PATH', plugin_dir_path( __FILE__ ) );
    … …  
    4040add_action( 'plugins_loaded', array( \Vabelon\Plugin::class, 'boot' ) );
    4141
    42 /**
    43  * Print the language switcher. For use in theme templates.
    44  *
    45  * @return void
    46  */
     42/** @return void */
    4743function vabelon_switcher(): void {
    4844        do_action( 'vabelon_switcher' );
    4945}
    5046
    51 /**
    52  * Address prefix of the language the current request is for.
    53  *
    54  * @return string
    55  */
     47/** @return string */
    5648function vabelon_current_language(): string {
    5749        return \Vabelon\Plugin::request()->language();
    5850}
    5951
    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>> */
    6553function vabelon_languages(): array {
    6654        return array_values( array_map( 'get_object_vars', \Vabelon\Plugin::languages()->all() ) );
    … …  
    6856
    6957/**
    70  * The language a post was given, or null when it has none and is shown as the default language.
    71  *
    7258 * @param int $post_id Post ID.
    7359 * @return string|null
    … …  
    7864
    7965/**
    80  * A post and its translations, as language address prefix => post ID.
    81  *
    8266 * @param int               $post_id  Post ID.
    8367 * @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.