This article documents the internals of the wpresidence-translate Settings screen: how it is registered, how its form fields map to the wpr_translate_settings option, and how the sanitizer validates each key. It pairs with the user-facing Settings walkthrough and the multi-language real estate website product page.
Page Registration
The Settings submenu is registered in includes/admin/menu.php by wpr_translate_admin_register_menus():
add_submenu_page(
'wpr-translate-overview',
__( 'Translation Settings', 'wpr-translate' ),
__( 'Settings', 'wpr-translate' ),
'manage_options',
'wpr-translate-settings',
'wpr_translate_admin_render_settings_page'
);
Capability is manage_options. The render callback loads the view file includes/admin/views/settings.php, which in turn includes the settings-delete-translations.php partial.
Settings API Bindings
wpr_translate_admin_register_settings() binds four option groups via register_setting():
register_setting( 'wpr_translate_languages', 'wpr_translate_languages', 'wpr_translate_admin_sanitize_languages' );
register_setting( 'wpr_translate_settings', 'wpr_translate_settings', 'wpr_translate_admin_sanitize_settings' );
register_setting( 'wpr_translate_glossary', 'wpr_translate_glossary', 'wpr_translate_admin_sanitize_glossary' );
register_setting( 'wpr_translate_auto_translation', 'wpr_translate_auto_translation', 'wpr_translate_admin_sanitize_auto_translation_settings' );
The Settings screen form uses settings_fields( 'wpr_translate_settings' ) and posts to options.php, so all validation goes through wpr_translate_admin_sanitize_settings().
Shape of wpr_translate_settings
After sanitization the option stores the following associative array:
| Key | Type | Default | Notes |
|---|---|---|---|
default_language |
string | site locale | Language code (e.g. en, fr). |
url_strategy |
string | subdirectory |
Sanitizer forces this value regardless of input. |
sync_media |
bool | true | Clone attachments metadata when duplicating content. |
elementor_compatibility |
bool | true | Enables Elementor widget and WPResidence shortcode ID remapping. |
taxonomy_modes |
array<string,string> | [] |
Per-taxonomy translate or not_translatable. Written by the Taxonomy Translation page, surfaced here as hidden fields. |
taxonomy_auto_duplicate |
array<string,bool> | [] |
Per-taxonomy auto-duplicate flag. Hidden fields. |
menu_language_switcher |
array<string,string> | [] |
Maps registered menu location to before or after. |
Keys written by the activator (enable_url_prefix, detect_browser_language, language_switcher_style) survive alongside the UI-managed keys because the sanitizer does not prune unknown keys.
Sanitizer Behavior
wpr_translate_admin_sanitize_settings() in includes/admin/settings-helpers.php:
wp_parse_args()merges the submitted payload with the defaults shown above.default_languageis passed throughsanitize_text_field()— non-Latin language codes are preserved.url_strategyis always overwritten tosubdirectory— other values are silently dropped.sync_mediaandelementor_compatibilityare cast tobool.auto_update_glossaryis explicitlyunset()(it was a previous-release key).taxonomy_modeskeys are run throughsanitize_key(); values must betranslateornot_translatable, otherwise they default totranslate.taxonomy_auto_duplicatevalues are cast tobool.menu_language_switcherentries are filtered againstget_registered_nav_menus()— unregistered locations are dropped. Positions must bebeforeorafter.
Form Fields in settings.php
Every visible field maps 1:1 to a sanitizer key:
| Control | Field name |
|---|---|
Default language <select> |
wpr_translate_settings[default_language] |
URL strategy <input type="radio"> |
wpr_translate_settings[url_strategy] |
Media sync <input type="checkbox"> |
wpr_translate_settings[sync_media] |
Elementor compat <input type="checkbox"> |
wpr_translate_settings[elementor_compatibility] |
Menu switcher <select> per location |
wpr_translate_settings[menu_language_switcher][{location}] |
| Taxonomy modes (hidden) | wpr_translate_settings[taxonomy_modes][{taxonomy}] |
| Taxonomy auto-duplicate (hidden) | wpr_translate_settings[taxonomy_auto_duplicate][{taxonomy}] |
The taxonomy inputs render as hidden fields so the values written by the Taxonomy Translation screen are preserved on Save.
Auxiliary Forms on the Same Page
Two additional forms render below the main settings form:
- Reset form — posts back to
admin.php?page=wpr-translate-settingswith nonce actionwpr_translate_reset_settings. Handled bywpr_translate_admin_handle_reset_settings()onadmin_init, which callswpr_translate_admin_reset_plugin_data(). - Delete Translations card — purely AJAX. Uses the nonce action
wpr_translate_delete_translationsand hitswp_ajax_wpr_translate_count_translationsandwp_ajax_wpr_translate_delete_translations(seeincludes/admin/delete-translations.php).
Reading Settings From Code
When you need the plugin’s current configuration inside other code, read the option directly:
$settings = get_option( 'wpr_translate_settings', array() );
$default = isset( $settings['default_language'] ) ? $settings['default_language'] : 'en';
$sync = ! empty( $settings['sync_media'] );
There is no dedicated getter helper — the option is intentionally a plain array so it is easy to inspect.
Related Options
| Option | Shape | Written by |
|---|---|---|
wpr_translate_languages |
indexed array of language payloads | Languages page sanitizer. |
wpr_translate_language_catalog |
predefined language list | Activator; merged with stored overrides on the Languages page. |
wpr_translate_auto_translation |
provider config | Automatic Translation page sanitizer. |
wpr_translate_glossary |
array of glossary entries | Glossary storage. |
Gotchas
- The
url_strategyradio group is cosmetic — the sanitizer hard-codessubdirectory. Do not build features that branch on other values until the plugin exposes them. - The sanitizer does not prune unknown keys left over from the activator (
enable_url_prefix,detect_browser_language,language_switcher_style). They coexist with UI-managed keys. - Saving the Languages page also calls
flush_rewrite_rules()— saving the Settings page does not. If your code changes URL behavior, flush rewrites yourself. - Menu-switcher locations that are no longer registered are silently dropped. Re-saving the form is enough to prune stale entries.
Extension Points
- Add additional keys to the option by extending the submitted form, then re-implementing the sanitizer — overriding
wpr_translate_admin_sanitize_settings()from a mu-plugin is the cleanest path. - Use the
wpr_translate_auto_translation_excluded_post_typesfilter (defined insettings-helpers.php) to exclude additional post types from automatic translation flows.
Further Reading
- Installation, Activation & Uninstall (Developer) — how the defaults in
wpr_translate_settingsare seeded. - Cache Purge & Reset Tools (Developer) — the reset, delete, and cache-purge endpoints.
- URL Structure & Permalinks — how the subdirectory strategy is implemented.
For the product framing around these options, see the multi-language real estate website page.