jpkcom_simplelang_abilities_enabled()
Decide whether the abilities should be registered at all.
jpkcom_simplelang_abilities_enabled() : bool
-
since
-
1.3.0
Return values
bool
—
True when registration should proceed.
jpkcom_simplelang_ability_log()
Write a debug line, and only with WP_DEBUG.
jpkcom_simplelang_ability_log(string $message) : void
Parameters
-
$message
: string
-
-
since
-
1.3.0
jpkcom_simplelang_ability_error()
Build a WP_Error carrying an HTTP status.
jpkcom_simplelang_ability_error(string $code, string $message[, int $status = 400 ]) : WP_Error
Without data['status'] rest_ensure_response() defaults to 500, and a 5xx
tells an agent "transient fault, retry unchanged" - the opposite of what a
caller mistake needs to hear.
Parameters
-
$code
: string
-
-
$message
: string
-
-
$status
: int
= 400
-
-
since
-
1.3.0
jpkcom_simplelang_ability_boundary()
Turn a Throwable out of a callback into a WP_Error.
jpkcom_simplelang_ability_boundary(callable $body, string $ability) : array<string, mixed>|WP_Error
Parameters
-
$body
: callable
-
-
$ability
: string
-
-
since
-
1.3.0
Return values
array<string, mixed>|WP_Error
—
jpkcom_simplelang_ability_json_object()
Wrap an empty map so it encodes as {} rather than [].
jpkcom_simplelang_ability_json_object(array<string, mixed> $map) : array<string, mixed>|stdClass
Parameters
-
$map
: array<string, mixed>
-
-
since
-
1.3.0
Return values
array<string, mixed>|stdClass
—
jpkcom_simplelang_ability_capability()
Check the capability required to run an ability.
jpkcom_simplelang_ability_capability(string $ability) : bool
edit_posts, not read. This reports an editorial and SEO condition of
the site - which pages are annotated for which language, and where that
annotation comes out incomplete - and it names unpublished and dangling
posts while doing so. That is not visitor-facing content.
Parameters
-
$ability
: string
-
-
since
-
1.3.0
Return values
bool
—
True when the current user may run it.
Build the meta array for an ability.
jpkcom_simplelang_ability_meta(string $ability) : array<string, mixed>
All three annotations explicit: they default to null and the REST run
controller derives the HTTP verb from them, so without readonly the run
route would be POST-only.
Parameters
-
$ability
: string
-
-
since
-
1.3.0
Return values
array<string, mixed>
—
Bring the value core hands the callback into array form.
jpkcom_simplelang_ability_normalise_input(mixed $input) : array<string, mixed>|null
normalize_input() substitutes the schema's top-level default when the input
is exactly null, and that default is a stdClass - so the callback receives
an object and must read it.
Parameters
-
$input
: mixed
-
-
since
-
1.3.0
Return values
array<string, mixed>|null
—
Array form, or null when unusable.
Refuse a top-level input key the ability does not declare.
jpkcom_simplelang_ability_validate_input_keys(array<string, mixed> $input, array<string|int, string> $allowed) : true|WP_Error
On EVERY ability, not a subset: a caller that learned the refusal on one
assumes it everywhere, and the ability that silently accepts is the one it
will trust.
Parameters
-
$input
: array<string, mixed>
-
-
$allowed
: array<string|int, string>
-
-
since
-
1.3.0
Return values
true|WP_Error
—
True when every key is declared.
jpkcom_simplelang_ability_enabled_post_types()
The post types language selection is enabled for.
jpkcom_simplelang_ability_enabled_post_types() : array<string|int, string>
Reads the same option and the same default the rest of the plugin reads,
rather than restating either.
Tags
-
since
-
1.3.0
Return values
array<string|int, string>
—
jpkcom_simplelang_ability_describe_locale()
Describe a locale the way the front end resolves it.
jpkcom_simplelang_ability_describe_locale(string $locale, array<string|int, string> $installed) : array<string, mixed>
installed matters more than it looks: a locale whose language pack was
removed stays in the post meta, and switch_to_locale() then returns false,
so the front end deliberately does NOT switch. The page keeps the site
language while its meta still claims another one.
Parameters
-
$locale
: string
-
Locale, or '' for "no language of its own".
-
$installed
: array<string|int, string>
-
-
since
-
1.3.0
Return values
array<string, mixed>
—
jpkcom_simplelang_ability_list_languages_inner()
Report which languages this site actually uses.
jpkcom_simplelang_ability_list_languages_inner([mixed $input = null ]) : array<string, mixed>|WP_Error
Parameters
-
$input
: mixed
= null
-
-
since
-
1.3.0
Return values
array<string, mixed>|WP_Error
—
jpkcom_simplelang_ability_build_sets()
Collect the translation sets on this site.
jpkcom_simplelang_ability_build_sets(array<string|int, string> $types) : array{sets: array, scanned: int, truncated: bool}
A set is a post plus everything it links to. Because the links are
bidirectional, the same set is reachable from each of its members, so sets
are deduplicated by their sorted member list.
Parameters
-
$types
: array<string|int, string>
-
-
since
-
1.3.0
Return values
array{sets: array, scanned: int, truncated: bool}
—
jpkcom_simplelang_ability_inspect_set()
Report what the hreflang output for one set will and will not contain.
jpkcom_simplelang_ability_inspect_set(array<string|int, int> $members, string $default_tag, array<string|int, string> $installed) : array<string, mixed>
Every finding below is derived from what the emitter does, not from an
opinion about what it should do:
- It keys entries by BCP 47 tag and keeps the FIRST per tag, so two members
resolving to one tag yield one entry and the other URL is annotated
nowhere. Which of the two survives depends on the order the posts come
back in, so this reports the collision and does NOT claim a winner.
- A member with no language of its own is read as the site default, so it
collides with an explicit member in that language rather than being
ignored.
- x-default is emitted only when some member carries the site default tag.
- Only published posts are fetched, so an unpublished member never appears.
Parameters
-
$members
: array<string|int, int>
-
-
$default_tag
: string
-
-
$installed
: array<string|int, string>
-
-
since
-
1.3.0
Return values
array<string, mixed>
—
jpkcom_simplelang_ability_check_sets_inner()
Report the translation sets whose hreflang output comes out incomplete.
jpkcom_simplelang_ability_check_sets_inner([mixed $input = null ]) : array<string, mixed>|WP_Error
Parameters
-
$input
: mixed
= null
-
-
since
-
1.3.0
Return values
array<string, mixed>|WP_Error
—
jpkcom_simplelang_ability_permission_list_languages()
Permission callback for list-languages.
jpkcom_simplelang_ability_permission_list_languages([mixed $input = null ]) : bool
Parameters
-
$input
: mixed
= null
-
-
since
-
1.3.0
Return values
bool
—
True when the current user may run it.
jpkcom_simplelang_ability_permission_check_sets()
Permission callback for check-translation-sets.
jpkcom_simplelang_ability_permission_check_sets([mixed $input = null ]) : bool
Parameters
-
$input
: mixed
= null
-
-
since
-
1.3.0
Return values
bool
—
True when the current user may run it.
jpkcom_simplelang_ability_list_languages()
Execute callback for jpkcom-simple-lang/list-languages.
jpkcom_simplelang_ability_list_languages([mixed $input = null ]) : array<string, mixed>|WP_Error
Parameters
-
$input
: mixed
= null
-
-
since
-
1.3.0
Return values
array<string, mixed>|WP_Error
—
jpkcom_simplelang_ability_check_sets()
Execute callback for jpkcom-simple-lang/check-translation-sets.
jpkcom_simplelang_ability_check_sets([mixed $input = null ]) : array<string, mixed>|WP_Error
Parameters
-
$input
: mixed
= null
-
-
since
-
1.3.0
Return values
array<string, mixed>|WP_Error
—
jpkcom_simplelang_get_ability_definitions()
Build the registration arguments for both abilities.
jpkcom_simplelang_get_ability_definitions() : array<string, array<string, mixed>>
Reads no WordPress state and touches no registry, which is what lets the CI
harness assert the shape of these arrays without a WordPress installation.
-
since
-
1.3.0
Return values
array<string, array<string, mixed>>
—
Ability name => registration args.
jpkcom_simplelang_register_ability_category()
Register the shared category, unless a sibling plugin already did.
jpkcom_simplelang_register_ability_category() : void
-
since
-
1.3.0
jpkcom_simplelang_register_abilities()
Register both abilities.
jpkcom_simplelang_register_abilities() : void
wp_register_ability() returns null on EVERY failure path and reports only
through _doing_it_wrong(), which is silent in production - and so is the
debug log without WP_DEBUG.
-
since
-
1.3.0
jpkcom_simplelang_sanitize_post_types()
Sanitize post types array
jpkcom_simplelang_sanitize_post_types(array<int, string>|null $value) : array<int, string>
Ensures only valid post types are saved in the settings.
Parameters
-
$value
: array<int, string>|null
-
The post types array to sanitize.
Tags
-
since
-
1.0.0
Return values
array<int, string>
—
Sanitized array of valid post types.
jpkcom_simplelang_enabled_post_types_field()
Render enabled post types field
jpkcom_simplelang_enabled_post_types_field() : void
Displays checkboxes for all public post types.
Tags
-
since
-
1.0.0
jpkcom_simplelang_settings_page()
Render settings page
jpkcom_simplelang_settings_page() : void
Displays the admin settings page for Simple Lang plugin.
Tags
-
since
-
1.0.0
jpkcom_simplelang_get_language_code()
Convert locale to language code
jpkcom_simplelang_get_language_code(string $locale) : string
Converts a locale string (e.g., de_DE) to a language code (e.g., de).
Kept for backwards compatibility. For markup that needs a language tag use
jpkcom_simplelang_get_bcp47() instead — a bare subtag cannot express
de-DE versus de-AT, and hreflang needs that distinction.
Parameters
-
$locale
: string
-
-
since
-
1.0.0
jpkcom_simplelang_get_bcp47()
Convert a WordPress locale to a BCP 47 language tag
jpkcom_simplelang_get_bcp47(string $locale) : string
de_DE becomes de-DE, en_US becomes en-US, ca stays ca. WordPress
variant suffixes carry no BCP 47 meaning and are dropped, so de_DE_formal
and de_CH_informal become de-DE and de-CH, and pt_PT_ao90 becomes
pt-PT — a formal and an informal German page are the same language and
region as far as a search engine is concerned.
Parameters
-
$locale
: string
-
The WordPress locale (e.g. 'de_DE', 'de_DE_formal').
-
since
-
1.2.9
Return values
string
—
The BCP 47 tag (e.g. 'de-DE').
jpkcom_simplelang_get_current_language()
Get current frontend language
jpkcom_simplelang_get_current_language() : string|null
Returns the currently active language for the frontend.
-
since
-
1.0.0
Return values
string|null
—
The current language locale or null if using site default.
jpkcom_simplelang_get_site_default_locale()
Get site default locale
jpkcom_simplelang_get_site_default_locale() : string
Returns the site's default locale, ignoring any temporary locale switches.
This is the locale set in Settings > General.
-
since
-
1.1.0
Return values
string
—
The site default locale (e.g., 'de_DE', 'en_US').
jpkcom_simplelang_get_language_name()
Get language name from locale
jpkcom_simplelang_get_language_name(string $locale) : string
Converts a locale code to a human-readable language name.
Parameters
-
$locale
: string
-
The locale code (e.g., 'de_DE', 'fr_FR').
-
since
-
1.1.0
Return values
string
—
The language name in native language.
jpkcom_simplelang_group_posts_by_language()
Group posts by language
jpkcom_simplelang_group_posts_by_language(array<string, mixed> $query_args) : array<string, array<int, WP_Post>>
Queries posts and groups them by their assigned language for display
in the translation links meta box.
Parameters
-
$query_args
: array<string, mixed>
-
Tags
-
since
-
1.1.0
Return values
array<string, array<int, WP_Post>>
—
jpkcom_simplelang_validate_translations()
Validate translation links
jpkcom_simplelang_validate_translations(int $post_id, array<string|int, int> $translation_ids) : array<string|int, int>
Ensures that translation links are valid and prevents duplicate languages.
Parameters
-
$post_id
: int
-
-
$translation_ids
: array<string|int, int>
-
Array of translation post IDs.
-
since
-
1.1.0
Return values
array<string|int, int>
—
Validated array of translation post IDs.
jpkcom_simplelang_get_translation_posts()
Get translation posts efficiently
jpkcom_simplelang_get_translation_posts(array<string|int, int> $post_ids) : array<string|int, WP_Post>
Fetches multiple posts in a single query to avoid N+1 query problems.
Parameters
-
$post_ids
: array<string|int, int>
-
Array of post IDs to fetch.
Tags
-
since
-
1.1.0
Return values
array<string|int, WP_Post>
—
jpkcom_simplelang_sync_translations()
Sync translation links bidirectionally
jpkcom_simplelang_sync_translations(int $post_id, array<string|int, int> $new_translations) : void
Updates translation links for the current post and ensures all posts in the
translation set are linked to each other. Creates a complete translation set
where every post links to all others in the set.
Parameters
-
$post_id
: int
-
-
$new_translations
: array<string|int, int>
-
Array of translation post IDs.
-
since
-
1.1.0
Render translation links meta box
jpkcom_simplelang_render_translations_meta_box(WP_Post $post) : void
Displays a multi-select dropdown with posts grouped by language.
Parameters
-
$post
: WP_Post
-
-
since
-
1.1.0
Generate and output hreflang tags
jpkcom_simplelang_output_hreflang_tags(int $post_id, array<string|int, int> $translation_ids) : void
Creates hreflang link tags for all translations including the current post.
Parameters
-
$post_id
: int
-
-
$translation_ids
: array<string|int, int>
-
Array of translation post IDs.
-
since
-
1.1.0
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
-
-
since
-
1.0.0
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
-
-
since
-
1.2.9
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
-
since
-
1.0.0
Return values
string|null
—
The language locale or null if not set.
jpkcom_simplelang_get_oxygen_language_options()
Get language options for Oxygen Builder
jpkcom_simplelang_get_oxygen_language_options() : array<string, string>
Returns an array of available languages formatted for Oxygen Builder conditions.
-
since
-
1.0.0
Return values
array<string, string>
—
Array of language codes and names.
jpkcom_simplelang_oxygen_post_language_is()
Oxygen condition callback: Post language is specific value
jpkcom_simplelang_oxygen_post_language_is(string $value, string $operator) : bool
Checks if the post has a specific language set.
Parameters
-
$value
: string
-
The language code to check.
-
$operator
: string
-
The comparison operator (== or !=).
Tags
-
since
-
1.0.0
Return values
bool
—
True if the condition matches.
jpkcom_simplelang_oxygen_has_custom_language()
Oxygen condition callback: Post has custom language
jpkcom_simplelang_oxygen_has_custom_language(string $value, string $operator) : bool
Checks if the post has any custom language set (not using site default).
Parameters
-
$value
: string
-
The value to check ('true' or 'false').
-
$operator
: string
-
The comparison operator (always ==).
-
since
-
1.0.0
Return values
bool
—
True if the condition matches.
jpkcom_simplelang_oxygen_uses_default_language()
Oxygen condition callback: Post uses default language
jpkcom_simplelang_oxygen_uses_default_language(string $value, string $operator) : bool
Checks if the post is using the site default language (no custom language set).
Parameters
-
$value
: string
-
The value to check ('true' or 'false').
-
$operator
: string
-
The comparison operator (always ==).
-
since
-
1.0.0
Return values
bool
—
True if the condition matches.
jpkcom_simplelang_textdomain()
Load plugin text domain for translations
jpkcom_simplelang_textdomain() : void
Loads translation files from the /languages directory.
Tags
-
since
-
1.0.0
jpkcom_simplelang_locate_file()
Locate file with override support
jpkcom_simplelang_locate_file(string $filename) : string|null
Searches for a file in multiple locations with priority:
- Child theme
- Parent theme
- MU plugin overrides
- Plugin includes directory
Parameters
-
$filename
: string
-
The filename to locate (without path).
-
since
-
1.0.0
Return values
string|null
—
Full path to the file if found, null otherwise.