WP Residence Help WP Residence Help

  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API
Home / WPResidence Translate Plugin / Settings Page — Developer Reference

Settings Page — Developer Reference

62 views 0

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:

  1. wp_parse_args() merges the submitted payload with the defaults shown above.
  2. default_language is passed through sanitize_text_field() – non-Latin language codes are preserved.
  3. url_strategy is always overwritten to subdirectory – other values are silently dropped.
  4. sync_media and elementor_compatibility are cast to bool.
  5. auto_update_glossary is explicitly unset() (it was a previous-release key).
  6. taxonomy_modes keys are run through sanitize_key(); values must be translate or not_translatable, otherwise they default to translate.
  7. taxonomy_auto_duplicate values are cast to bool.
  8. menu_language_switcher entries are filtered against get_registered_nav_menus() – unregistered locations are dropped. Positions must be before or after.

Screenshot: Browser devtools network tab showing options.php POST with wpr_translate_settings payload

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:

  1. Reset form – posts back to admin.php?page=wpr-translate-settings with nonce action wpr_translate_reset_settings. Handled by wpr_translate_admin_handle_reset_settings() on admin_init, which calls wpr_translate_admin_reset_plugin_data().
  2. Delete Translations card – purely AJAX. Uses the nonce action wpr_translate_delete_translations and hits wp_ajax_wpr_translate_count_translations and wp_ajax_wpr_translate_delete_translations (see includes/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_strategy radio group is cosmetic – the sanitizer hard-codes subdirectory. 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_types filter (defined in settings-helpers.php) to exclude additional post types from automatic translation flows.

Further Reading

  • Installation, Activation & Uninstall (Developer) – how the defaults in wpr_translate_settings are 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.

WPResidence Translate Plugin

Related Articles

  • String Scanner — Developer Guide
  • The String Scanner
  • Gettext Pipeline & MO Files — Developer Guide
  • Gettext & MO Files — Making Translations Appear on the Front End

Help Categories

  • 18Agent, Agency & Developers
  • 5Blog Posts & Blog Lists
  • 38Elementor Shortcodes Built-In
  • 45FAQ
  • 15Footer
  • 5Getting Started
  • 37Header
  • 2IDX & MLSImport
  • 6Installation & Setup
  • 23Installation FAQ
  • 23Maps & Location Settings
  • 21Multi-Language Third Party Plugins
  • 6Other Third party Plugins
  • 19Pages
  • 4Payments & Monetization
  • 20Property Lists, Categories & Archive
  • 36Property Pages & Layouts
  • 31Search & Filtering
  • 162Technical how to | Custom Code Required
  • 8Technical: Actions and filters
  • 6Technical: Child Theme
  • 86Theme Options & Global Settings
  • 6Translations & Languages
  • 16WPBakery Shortcodes
  • 51WPResidence / WPEstate CRM
  • 50WPResidence 5.0 Documentation
  • 8WPResidence Elementor Studio
  • 50WPResidence Translate Plugin

Join Us On

Powered by WP Estate - All Rights Reserved
  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API