meta-box.php
Language Selection Meta Box
Adds a meta box to post edit screens for selecting the frontend language.
Tags
Table of Contents
Functions
- jpkcom_simplelang_render_meta_box() : void
- Render language selection meta box
- jpkcom_simplelang_is_valid_locale() : bool
- Check whether a locale may be stored as a post language
- jpkcom_simplelang_get_post_language() : string|null
- Get post language
Functions
jpkcom_simplelang_render_meta_box()
Render language selection meta box
jpkcom_simplelang_render_meta_box(WP_Post $post) : void
Displays a dropdown with all available WordPress languages.
Parameters
- $post : WP_Post
-
Current post object.
Tags
jpkcom_simplelang_is_valid_locale()
Check whether a locale may be stored as a post language
jpkcom_simplelang_is_valid_locale(string $locale) : bool
Validated against the locales WordPress actually has installed, plus en_US,
which needs no language pack. That is the same list the meta box builds its
options from, so anything offered can also be saved.
Up to 1.2.8 this was a regex, /^[a-z]{2,3}(_[A-Z]{2})?$/, which silently
rejected every WordPress variant locale: de_DE_formal, nl_NL_formal,
de_CH_informal, pt_PT_ao90 and art_xemoji. The meta box offered them,
save_post dropped them, and nothing said so — this plugin even ships
de_DE_formal translations of its own. A whitelist is both stricter (no
invented locales) and complete (every real one).
Parameters
- $locale : string
-
The locale to check.
Tags
Return values
bool —True when the locale may be stored.
jpkcom_simplelang_get_post_language()
Get post language
jpkcom_simplelang_get_post_language([int|null $post_id = null ]) : string|null
Retrieves the language set for a specific post.
Parameters
- $post_id : int|null = null
-
Optional. Post ID. Defaults to current post.
Tags
Return values
string|null —The language locale or null if not set.