API Documentation
Table of Contents
Namespaces
Constants
- JPKCOM_SIMPLELANG_BASENAME = \plugin_basename(__FILE__)
- JPKCOM_SIMPLELANG_PLUGIN_PATH = \plugin_dir_path(__FILE__)
- JPKCOM_SIMPLELANG_PLUGIN_URL = \plugin_dir_url(__FILE__)
- JPKCOM_SIMPLELANG_VERSION = '1.1.1'
Functions
- jpkcom_simplelang_sanitize_post_types() : array<int, string>
- Sanitize post types array
- jpkcom_simplelang_enabled_post_types_field() : void
- Render enabled post types field
- jpkcom_simplelang_settings_page() : void
- Render settings page
- jpkcom_simplelang_get_language_code() : string
- Convert locale to language code
- jpkcom_simplelang_get_current_language() : string|null
- Get current frontend language
- jpkcom_simplelang_get_site_default_locale() : string
- Get site default locale
- jpkcom_simplelang_get_language_name() : string
- Get language name from locale
- jpkcom_simplelang_group_posts_by_language() : array<string, array<int, WP_Post>>
- Group posts by language
- jpkcom_simplelang_validate_translations() : array<string|int, int>
- Validate translation links
- jpkcom_simplelang_get_translation_posts() : array<string|int, WP_Post>
- Get translation posts efficiently
- jpkcom_simplelang_sync_translations() : void
- Sync translation links bidirectionally
- jpkcom_simplelang_render_translations_meta_box() : void
- Render translation links meta box
- jpkcom_simplelang_output_hreflang_tags() : void
- Generate and output hreflang tags
- jpkcom_simplelang_render_meta_box() : void
- Render language selection meta box
- jpkcom_simplelang_get_post_language() : string|null
- Get post language
- jpkcom_simplelang_get_oxygen_language_options() : array<string, string>
- Get language options for Oxygen Builder
- jpkcom_simplelang_oxygen_post_language_is() : bool
- Oxygen condition callback: Post language is specific value
- jpkcom_simplelang_oxygen_has_custom_language() : bool
- Oxygen condition callback: Post has custom language
- jpkcom_simplelang_oxygen_uses_default_language() : bool
- Oxygen condition callback: Post uses default language
- jpkcom_simplelang_textdomain() : void
- Load plugin text domain for translations
- jpkcom_simplelang_locate_file() : string|null
- Locate file with override support
Constants
JPKCOM_SIMPLELANG_BASENAME
public
mixed
JPKCOM_SIMPLELANG_BASENAME
= \plugin_basename(__FILE__)
JPKCOM_SIMPLELANG_PLUGIN_PATH
public
mixed
JPKCOM_SIMPLELANG_PLUGIN_PATH
= \plugin_dir_path(__FILE__)
JPKCOM_SIMPLELANG_PLUGIN_URL
public
mixed
JPKCOM_SIMPLELANG_PLUGIN_URL
= \plugin_dir_url(__FILE__)
JPKCOM_SIMPLELANG_VERSION
public
mixed
JPKCOM_SIMPLELANG_VERSION
= '1.1.1'
Functions
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
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
jpkcom_simplelang_settings_page()
Render settings page
jpkcom_simplelang_settings_page() : void
Displays the admin settings page for Simple Lang plugin.
Tags
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).
Parameters
- $locale : string
-
The locale string.
Tags
Return values
string —The language code.
jpkcom_simplelang_get_current_language()
Get current frontend language
jpkcom_simplelang_get_current_language() : string|null
Returns the currently active language for the frontend.
Tags
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.
Tags
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').
Tags
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>
-
WP_Query arguments.
Tags
Return values
array<string, array<int, WP_Post>> —Posts grouped by locale.
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
-
The current post ID.
- $translation_ids : array<string|int, int>
-
Array of translation post IDs.
Tags
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
Return values
array<string|int, WP_Post> —Array of post objects.
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
-
The post ID to sync.
- $new_translations : array<string|int, int>
-
Array of translation post IDs.
Tags
jpkcom_simplelang_render_translations_meta_box()
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
-
Current post object.
Tags
jpkcom_simplelang_output_hreflang_tags()
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
-
The current post ID.
- $translation_ids : array<string|int, int>
-
Array of translation post IDs.
Tags
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_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.
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.
Tags
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
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 ==).
Tags
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 ==).
Tags
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
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).
Tags
Return values
string|null —Full path to the file if found, null otherwise.