=== Ja Tate – 日本語縦 ===
Contributors: kengen
Tags: japanese, vertical writing, tategaki, writing-mode, admin
Requires at least: 7.1
Tested up to: 7.1
Requires PHP: 8.1
Stable tag: 0.1.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Adds “日本語縦” (Japanese, vertical writing) to the language lists. Choose it, and the whole admin is laid out in vertical writing.

== Description ==

Choosing Arabic turns the WordPress admin right-to-left. This plugin does the same for vertical Japanese: it adds the language **日本語縦** (locale `ja_tate`) right after 日本語 in Settings › General and in each user's profile. When it is selected, every classic admin screen is laid out in vertical writing (`writing-mode: vertical-rl`), like a newspaper page: lines run from top to bottom, one after the other from right to left, and the screen scrolls to the left.

* **Translations**: 日本語縦 reuses the installed Japanese (ja) language files of core, plugins and themes. Nothing has to be translated again.
* **Stylesheets**: the admin stylesheets (core and plugins) are turned a quarter at runtime — what was physical in horizontal writing is read as logical in vertical writing — and cached under `uploads/ja-tate/css/`. No build step: updates of core and plugins are followed automatically.
* **Frame**: the toolbar becomes a strip along the right edge, the admin menu a band along the top, the content flows below it from right to left. On the front end, a vertical theme that asks for it (`'admin-bar' => 'side'`, see “For theme authors” below; Tate does) gets the toolbar as a strip along the right edge too.
* **Islands**: the TinyMCE menus, dialogs and notices of the visual editor, the colour picker, the code editor, the link dialog, the media player, the thickbox windows, the jQuery UI dialogs, calendars and pointers, and the Customizer are vertical. Only a few parts stay horizontal (“islands”): the colour picture inside a TinyMCE dialog, colour pickers that cannot be taken over (another copy of Iris, Pz-LinkCard’s panel), what a window shows from another site (YouTube and Vimeo embeds, the theme update details), and editors that bring their own CodeMirror. A part whose script depends on core’s internals falls back to a horizontal island on a WordPress version other than the tested one (7.1), or when the site turns its filter off. Fonts and Connectors, built by scripts that inject their own CSS at runtime, are vertical too; on an untested version they keep their content horizontal inside the vertical frame.
* **Media**: the media modal, the library grid and the attachment details are vertical; the cells run down each line and the lines run to the left, and infinite scrolling loads more as you read on to the left. Their script corrections depend on core's internals, so on WordPress versions other than the tested ones (7.1) they stay horizontal (filter `ja_tate_media_vertical`). The arrow keys work as in core; the filter `ja_tate_media_options` (`keys`) makes them follow the vertical layout instead (↓ the next item, ← the next line). The menu and the tabs of the modal announce the direction they are laid out in (`aria-orientation`); by default their arrow keys stay core's (↓ for the next item of the menu, → for the next tab), and with `keys` the arrows of the announced direction move along them instead (in the menu, which runs from right to left, ← goes to the next item).
* **Upright numbers**: numbers of one to four digits in the admin's own text are set upright (縦中横); longer numbers, and numbers joined to other letters or digits by `.`, `,`, `:`, `/` or `-` (16.10.2026, 3:29, 1,000), stay sideways, so that one number is never half upright.
* **Classic editor**: while 日本語縦 is used, posts are edited in the classic editor (the block editor is out of scope). The editor itself is vertical. An `<iframe>` written in the text (a video's “embed code”, say) is shown in the visual editor as a box of its size that names its site, not as the frame itself: a frame of another site inside the editor could stop Chrome. The text is kept exactly as written (the code tab and the saved post have the `<iframe>`), and the page shows the frame. The editor's preview of an embed (a YouTube URL alone on a line, say) is drawn the same way when it holds a frame or a script of another site, or a sandboxed frame (core's card of a post of the site itself); the other previews of the site's own (audio and video players) are not changed.
* **An editor as long as the text**: the post's editor (the visual and the code tab) grows to the left with its text, as the horizontal editor grows downward: nothing scrolls inside it, the page scrolls instead, and the caret is kept in view. Its tools and toolbar stay at the right edge of the screen and the bar with the word count at the left while the text goes on under them (not on phone-sized or low windows, told by the window's size; with the second toolbar row, TinyMCE's status bar stays beside the word count). Screen Options › “Grow the editor to the length of its text.” turns it off for a user (it is core's full-height editor setting, shared with the horizontal admin). Filters: `ja_tate_editor_grow` (whether it grows; on the tested WordPress versions by default) and `ja_tate_editor_grow_sticky` (whether the bars stay on the screen).
* **Dates**: adds date formats in the Japanese era (令和8年9月25日), the imperial year (二六八六年9月25日) and Western years in kanji numerals (二〇二六年9月25日), with the month and day in kanji numerals too (令和八年十月十六日, 二〇二六年十一月卅日), and times like 14時30分. They are written with format characters that PHP's date() does not use: `K` (era and year, 令和8), `k` (short era, R8), `E` (午前/午後), `J` (Western year in kanji digits, 二〇二六), `Q` (imperial year, 二六八六), `R` (era and year in kanji numerals, 令和八), `V` (month, 十一), `b` (day, 二十三) and `f` (day with 廿 and 卅 for the twenties and thirties, 廿三, 卅一), as in `R年V月f日`; escape one with a backslash to print the letter itself. A format is saved for the whole site, so it is expanded for everyone as soon as the site, the request or any user is set to 日本語 or 日本語縦. The monthly archives (the Archives widget, the archive title and the calendar caption) follow the year and month of the chosen format (二六八六年十月). In Settings › General the standard formats of the language stay first, and the format in use is added as a separate entry.
* **Fewer image copies**: a vertical theme can ask for fewer copies of each uploaded image (`'image-sizes' => 'fewer'`, see “For theme authors” below; Tate does). In vertical writing a picture is bounded by the height of the line, and WordPress re-encodes every copy, so a copy close to the size of a photo that was already exported small can weigh as much as the photo, or more. The plugin then makes thumbnail, medium, large and the theme's own sizes, but not medium_large (768), nor 1536x1536 and 2048x2048 for an image of 2560 px or less on its longer side; high-density screens are offered the uploaded image itself instead. A larger image (the big-image threshold turned off or raised for it) gets them as usual, and an image that already has these copies keeps them up to date in the image editor. This is data in the media library, so it is done by the plugin rather than the theme. Existing copies are neither removed nor remade. Filters: `ja_tate_fewer_image_sizes` (whether to do it; default: whether the active theme asks) and `ja_tate_skipped_image_sizes` (the sizes left out; an empty array makes them all). The escape hatches below do not change it: they stop the layout, and the copies are data in the media library; use the filter. `wp ja-tate status` shows whether it is on, and why.

A theme that is always vertical, **Tate**, is available separately.

= For theme authors =

A vertical theme tells the plugin that its front end is vertical with the theme feature `ja-tate-vertical`, and asks for what it wants with the arguments of that feature, **all in one call**, as Tate does:

`add_theme_support( 'ja-tate-vertical', array( 'admin-bar' => 'side', 'image-sizes' => 'fewer', 'media-player' => 'vertical' ) );`

* `'admin-bar' => 'side'`: on the front end, the toolbar is drawn as a strip along the right edge. The theme moves its own fixed parts by the width of the strip, `--ja-tate-adminbar-size`, while `<body>` has the class `ja-tate-adminbar-vertical`.
* `'image-sizes' => 'fewer'`: fewer copies of each uploaded image (above).
* `'media-player' => 'vertical'`: the theme puts audio and video players in a box of a fixed width (Tate: `.masu-media`); the plugin opens that box when it turns the player vertical, and adds the class `ja-tate-mejs-vertical` to `<body>` (only on a page where MediaElement builds the player). Without the plugin, with the valve closed, or where MediaElement does not run, the box stays.

The filter `ja_tate_is_vertical` ( `$on`, `$context` ) gets the context `admin`, `login`, `admin-bar` (the toolbar on the front end) or `media-player`.

WordPress does not merge the arguments of a theme feature: each `add_theme_support( 'ja-tate-vertical', … )` replaces the arguments of the one before. Called once for the toolbar and once for the images, only the second request is kept. A child theme that adds an argument merges it into its parent's, on `after_setup_theme` after the parent (priority 11 or later): take the array from `get_theme_support( 'ja-tate-vertical' )[0]` (when it is an array), add the key, and call `add_theme_support()` again with the whole array. The plugin reads every argument through `current_theme_supports()`, so returning false from the core filter `current_theme_supports-ja-tate-vertical` turns them all off.

= Escape hatches =

If a screen breaks in vertical writing:

* add `?ja-tate=off` to any admin URL (remembered by a cookie; `?ja-tate=on` switches back), or `?ja-tate=off-once` for one request;
* define `JA_TATE_DISABLE` as `true` in `wp-config.php` (translations keep working, only the vertical layout stops);
* `wp ja-tate off` with WP-CLI;
* switch a user back to Japanese: `wp user meta update <user-id> locale ja`.

= Out of scope =

Multisite (first version), the block editor and the site editor. The block editor screens (the Site Editor, and screens of other plugins built on the block editor) are drawn horizontally as a whole (filter `ja_tate_block_editor_horizontal`). Tested with Chrome and Edge on every classic screen, and with Firefox 154–157 on the main screens and the vertical parts; in Firefox the drop-down lists open in the browser’s own horizontal way. Safari is not tested.

== Installation ==

1. Install the Japanese (日本語) language for WordPress first (Settings › General › Site Language).
2. Upload the plugin and activate it.
3. Choose 日本語縦 in Settings › General › Site Language, or only for yourself in your profile.

Deactivating the plugin switches every user and the site from 日本語縦 back to 日本語.

== Frequently Asked Questions ==

= Does <html lang> change? =

No. It stays `ja`: 日本語縦 is Japanese; only the layout differs.

= Why does the text direction stay left-to-right? =

`dir="rtl"` would make vertical lines run from bottom to top. The plugin keeps `ltr` and tells its own code about vertical writing with `ja_tate_is_vertical()`.

= Which image sizes suit a vertical theme? =

A photo aligned left or right sits at the top or bottom of a vertical line. Give the medium size a max height of a little less than half the longest line in Settings › Media, and a max width of 1024 (for Tate, whose longest line is 792 px: 1024 × 384), and insert aligned photos at the medium size: text then fills the other half of the line beside them. A landscape 4:3 photo becomes 512×384, so that a screen of twice the density is served the large copy (1024 px) rather than the uploaded image; the max width keeps a panorama from being wider than the large size. Insert large photos with the alignment “None”. The plugin does not change these settings.

= What happens to the images when I switch themes? =

Images uploaded while the theme asked for fewer copies keep the copies they have. With another theme (or without the plugin), new uploads get WordPress's usual copies. Of the older images, those wider than 2048 px (a landscape photo of 2560×1920, say) offer high-density screens at most their large copy until the missing copies are made: `wp media regenerate --image_size=2048x2048 --only-missing`, and the same with 1536x1536 and medium_large. Narrower ones (a portrait photo of 1920×2560) still offer the image itself, since WordPress lists images up to 2048 px wide in `srcset`. To keep fewer copies with another theme, return true from the `ja_tate_fewer_image_sizes` filter.

= Do the drop-down lists of the admin open vertically? =

In Chrome, Edge and other Chromium browsers, yes: the options of a drop-down list (`<select>`) stand as columns read from right to left. Firefox and browsers without the CSS `appearance: base-select` keep the browser's own horizontal list. Inside the media modal and the visual editor's dialogs they open vertically too; only a part that has fallen back to a horizontal island (see Islands above) opens its lists horizontally. To keep the browser's own lists everywhere, return false from the `ja_tate_vertical_select` filter; add `?ja-tate-select=native` to an admin address to see one screen with them.

= My site uses a full-page cache. Is there anything to watch? =

If your site uses a full-page cache (a caching plugin, a server-side or CDN HTML cache), the front end links the rotated copy of the media player's CSS (only when the theme asks for it). When WordPress core changes those files, the copy gets a new name, and the old copy is kept for 7 days so that cached pages keep working. Keep your page cache's lifetime within 7 days, or clear it after a WordPress update.

= Where are the generated stylesheets? =

In `wp-content/uploads/ja-tate/css/`. Copies not used for 30 days are removed by themselves while the admin is in use (the cache is swept when a copy is built, and when a copy in use is renewed, about once a week). `wp ja-tate css clear` removes them all; they are rebuilt on the next request that needs them (a browser keeps the stylesheets that scripts load at runtime for a day, and does not need the files meanwhile). Uninstalling the plugin removes the directory. On an admin served over https, the copies are linked over https too, and the fonts and images they refer to follow the page's scheme (a copy built by `wp ja-tate css build` or on an http page serves an https admin as well).

== Changelog ==

= 0.1.0 =
* First version.
