• Skip to primary navigation
  • Skip to main content

RocketGeek

Home of WP-Members, The Original WordPress Membership Plugin

  • WordPress Plugins
    • WP-Members
      • FAQs
      • Quick Start
      • Documentation
      • Extensions
    • Advanced Options
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Download Protect
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Invite Codes
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • MailChimp Integration
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • PayPal Subscriptions
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Salesforce Web-to-Lead
    • Security
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Text Editor
      • Purchase the Plugin
      • Get the Pro Bundle
    • User List
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • User Tracking
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Memberships for WooCommerce
    • WordPass
  • Blog
    • Basics
    • Tips and Tricks
    • Filters
    • Actions
    • Code Snippets
    • Shortcodes
    • Design
    • Release Announcements
  • Store
    • Cart
    • Checkout
  • Contact
  • Log In
  • Show Search
Hide Search
Home » Code Snippets » Filter register form custom fields for multiple languages

Filter register form custom fields for multiple languages

Chad Butler · Jun 11, 2018 ·

/**
 * Create a map for your custom field labels to be translated.
 * Set a new case for each language locale following the 
 * example set below. Each case should be an array where
 * the array key is the field's meta key and the value is
 * the translated text for that locale.
 *
 * Follow the example below where each array element is as follows:
 *
 *     'the_meta_key' => 'The translated value for the requested locale',
 *
 * The default value will simply return an empty array.
 */
function my_custom_translation_strings( $locale ) {
    switch ( $locale ) {
        
        case "de_DE":
            $string_map = array(
                'custom_field' => 'Benutzerdefinierte Feld',
                'other_custom_field' => 'Anderes benutzerdefiniertes Feld',
            );
            break;
            
        case "es_ES":
            $string_map = array(
                'custom_field' => 'Campo personalizado',
                'other_custom_field' => 'Otro campo personalizado',            
            );
            break;
        
        default:
            $string_map = array();
            break;
    }
    
    return $string_map;
}

/**
 * This will filter the register form labels and input tag
 * placeholders based on the translation string map returned 
 * for the requested locale.
 *
 * No changes are necessary to this filter.
 */
add_filter( 'wpmem_register_form_rows', 'apply_my_custom_translation' );
function apply_my_custom_translation( $rows ) {
    global $wpmem;
    $string_map = my_custom_translation_strings( get_locale() );
    if ( ! empty( $string_map ) ) {
        foreach ( $rows as $meta_key => $row ) {
            if ( array_key_exists( $meta_key, $string_map ) ) {
                $rows[ $meta_key ]['label'] = str_replace( $row['label_text'], $string_map[ $meta_key ], $row['label'] );
                $rows[ $meta_key ]['field'] = str_replace( 'placeholder="' . $wpmem->fields[ $meta_key ]['placeholder'] . '"', 'placeholder="' . $string_map[ $meta_key ] . '"', $row['field'] );
            }
        }
    }
    return $rows;
}

/**
 * Other filters may be used and or necessary depending on
 * actual application. This example just covers applying
 * additional translation to the register form labels. 
 * Messages, dialogs, login form, widget, those would all 
 * be separate filters. Note that you do only need to create
 * one single mapping function and you can use that fof
 * all of your translation filters.
 */

Not sure what to do with this code?

You're not a "coder" and don't know what to do? Don't worry! Code Snippets are the basic building blocks of WordPress customization, and once you know the basics, they are simple to use.

Here are some free articles to get you started:

  • Using Code Snippets from the Site
  • Using a code snippets plugin
  • The functions.php File
  • Create a plugin file for custom functions
  • Create a child theme
  • Do not modify plugin files!

For "hands on" help, consider a plugin support subscription or the Pro Bundle.

Ready to get started?

Join Today!

© 2025 · butlerblog.com · RocketGeek is built using WordPress, WP-Members, and the Genesis Framework

  • butlerblog.com
  • WP-Members Support Subscription
  • Terms of Service
  • Privacy Policy
  • Refund Policy