This document explains the specialized query handler classes that manage translation links for WordPress archive pages, including date-based archives (year, month, day), author archives, and custom post type archives. These handlers determine whether translated content exists in other language blogs and generate appropriate archive URLs.
For information about post and taxonomy translation links, see Options and Storage System. For the routing mechanism that selects these handlers, see Content Type Detection and Routing. For details on the SQL caching infrastructure, see Data Utilities and Caching.
The plugin provides five specialized query handler classes, each extending MslsOptionsQuery:
| Archive Type | Handler Class | Query Parameters |
|---|---|---|
| Year Archive | MslsOptionsQueryYear | year |
| Month Archive | MslsOptionsQueryMonth | year, monthnum |
| Day Archive | MslsOptionsQueryDay | year, monthnum, day |
| Author Archive | MslsOptionsQueryAuthor | author_id |
| Post Type Archive | MslsOptionsQueryPostType | post_type |
Each handler implements the same interface pattern: extracting query parameters, checking for translated content existence, and generating archive URLs.
Sources: includes/MslsOptionsQueryYear.php includes/MslsOptionsQueryMonth.php includes/MslsOptionsQueryDay.php includes/MslsOptionsQueryAuthor.php includes/MslsOptionsQueryPostType.php
Each concrete handler class inherits from MslsOptionsQuery and maintains a reference to MslsSqlCacher for database query optimization. The handlers store extracted query parameters as protected properties and implement three critical methods: get_params(), has_value(), and get_current_link().
Sources: includes/MslsOptionsQueryYear.php12-66 includes/MslsOptionsQueryMonth.php12-67 includes/MslsOptionsQueryDay.php12-72 includes/MslsOptionsQueryAuthor.php12-59 includes/MslsOptionsQueryPostType.php10-54 includes/MslsSqlCacher.php22-108
All archive query handlers depend on MslsSqlCacher to optimize database queries. The cacher is injected via the constructor and used when checking content existence across language blogs.
The MslsSqlCacher::create() factory method generates a cache key combining the caller name and query parameters includes/MslsSqlCacher.php66-74 The cacher intercepts get_var() and get_results() calls via __call(), checking WordPress object cache before executing SQL includes/MslsSqlCacher.php95-107
Sources: includes/MslsSqlCacher.php22-108
The three date archive handlers form a hierarchical pattern, with each level adding more specificity.
MslsOptionsQueryYear handles yearly archives (e.g., /2023/). It extracts the year query variable and uses YearPostsCounterQuery to determine if posts exist for that year in translated blogs.
Parameter Extraction: includes/MslsOptionsQueryYear.php37-41
Content Existence Check: includes/MslsOptionsQueryYear.php50-55
The has_value() method lazy-loads the post count using YearPostsCounterQuery and caches the result in the internal arr array indexed by language. It returns true if posts exist for that year.
Link Generation: includes/MslsOptionsQueryYear.php63-65
Uses WordPress's get_year_link() function to generate the canonical URL.
MslsOptionsQueryMonth handles monthly archives (e.g., /2023/05/), requiring both year and monthnum parameters.
Parameter Extraction: includes/MslsOptionsQueryMonth.php36-41
Content Existence Check: includes/MslsOptionsQueryMonth.php50-56
Uses MonthPostsCounterQuery to check if posts exist for the year-month combination in the translated blog.
Link Generation: includes/MslsOptionsQueryMonth.php64-66
Uses WordPress's get_month_link() function.
MslsOptionsQueryDay handles daily archives (e.g., /2023/05/15/), requiring year, monthnum, and day parameters.
Parameter Extraction: includes/MslsOptionsQueryDay.php39-45
Content Existence Check: includes/MslsOptionsQueryDay.php54-62
Uses DatePostsCounterQuery (note the different query class name) to check if posts exist for the specific date.
Link Generation: includes/MslsOptionsQueryDay.php69-71
Uses WordPress's get_day_link() function with all three parameters.
Sources: includes/MslsOptionsQueryYear.php includes/MslsOptionsQueryMonth.php includes/MslsOptionsQueryDay.php
MslsOptionsQueryAuthor manages author archive pages (e.g., /author/john-doe/).
Parameter Extraction: includes/MslsOptionsQueryAuthor.php30-34
Unlike date archives, the author handler uses get_queried_object_id() instead of get_query_var() to retrieve the author's user ID.
Content Existence Check: includes/MslsOptionsQueryAuthor.php43-48
Uses AuthorPostsCounterQuery to determine if the author has published posts in the translated blog. The query searches by author ID, which remains constant across blogs in a multisite network.
Link Generation: includes/MslsOptionsQueryAuthor.php56-58
Uses WordPress's get_author_posts_url() function with the author ID.
Sources: includes/MslsOptionsQueryAuthor.php
MslsOptionsQueryPostType manages custom post type archives (e.g., /products/).
Parameter Extraction: includes/MslsOptionsQueryPostType.php25-29
Extracts the post_type query variable, which contains the post type slug.
Content Existence Check: includes/MslsOptionsQueryPostType.php38-44
Unlike other handlers, this doesn't query for post counts. Instead, it checks if the post type object exists using WordPress's get_post_type_object(). This returns false if the post type isn't registered in the translated blog, allowing the plugin to hide language switcher links when a custom post type doesn't exist across all languages.
Link Generation: includes/MslsOptionsQueryPostType.php51-53
Uses WordPress's get_post_type_archive_link() function, which respects custom rewrite rules configured for the post type.
Sources: includes/MslsOptionsQueryPostType.php
This diagram illustrates the complete flow from WordPress query detection through handler instantiation, content checking, and link generation. The factory method selects the appropriate handler based on WordPress's conditional tags. Each handler extracts parameters from WordPress's query system, uses specialized query callables to check content existence (with SQL caching), and generates archive URLs using WordPress's permalink functions.
Sources: All files in the provided list
All handlers implement a static get_params() method that returns an associative array of query parameters. This design allows the factory to validate parameters before instantiating handlers.
| Handler | Parameters | WordPress Functions |
|---|---|---|
MslsOptionsQueryYear | ['year' => int] | get_query_var('year') |
MslsOptionsQueryMonth | ['year' => int, 'monthnum' => int] | get_query_var('year'), get_query_var('monthnum') |
MslsOptionsQueryDay | ['year' => int, 'monthnum' => int, 'day' => int] | get_query_var('year'), get_query_var('monthnum'), get_query_var('day') |
MslsOptionsQueryAuthor | ['author_id' => int] | get_queried_object_id() |
MslsOptionsQueryPostType | ['post_type' => string] | get_query_var('post_type') |
The constructor receives MslsSqlCacher and immediately calls get_params() to extract and store parameters as instance properties includes/MslsOptionsQueryYear.php26-30 includes/MslsOptionsQueryMonth.php24-31 includes/MslsOptionsQueryDay.php29-37 includes/MslsOptionsQueryAuthor.php21-25 includes/MslsOptionsQueryPostType.php19-23
Sources: includes/MslsOptionsQueryYear.php37-41 includes/MslsOptionsQueryMonth.php36-41 includes/MslsOptionsQueryDay.php39-45 includes/MslsOptionsQueryAuthor.php30-34 includes/MslsOptionsQueryPostType.php25-29
Each handler's get_current_link() method generates the canonical URL for the current archive using WordPress's built-in permalink functions:
get_year_link($year) includes/MslsOptionsQueryYear.php63-65get_month_link($year, $monthnum) includes/MslsOptionsQueryMonth.php64-66get_day_link($year, $monthnum, $day) includes/MslsOptionsQueryDay.php69-71get_author_posts_url($author_id) includes/MslsOptionsQueryAuthor.php56-58get_post_type_archive_link($post_type) includes/MslsOptionsQueryPostType.php51-53These methods return the current blog's archive URL. When generating language switcher links, MslsOutput calls this method after switching to each translated blog's context using WordPress's switch_to_blog() function, ensuring URLs respect each blog's permalink structure and rewrite rules.
Sources: includes/MslsOptionsQueryYear.php63-65 includes/MslsOptionsQueryMonth.php64-66 includes/MslsOptionsQueryDay.php69-71 includes/MslsOptionsQueryAuthor.php56-58 includes/MslsOptionsQueryPostType.php51-53
The date and author archive handlers delegate content existence checks to specialized query callable classes in the lloc\Msls\Query namespace:
Each query callable implements the __invoke() magic method, making instances callable as functions. They receive the SQL cacher instance in their constructor and execute optimized database queries to count posts matching the archive criteria.
Sources: includes/MslsOptionsQueryYear.php50-55 includes/MslsOptionsQueryMonth.php50-56 includes/MslsOptionsQueryDay.php54-62 includes/MslsOptionsQueryAuthor.php43-48
Refresh this wiki
This wiki was recently refreshed. Please wait 1 day to refresh again.