Purpose

Customize the locale used for a template. This filter allows you to dynamically adjust the locale based on specific conditions, such as user input or template type.

Usage

add_filter( "wr_get_template_locale", array( $this, "set_wp_language_by_registration_email" ), 20, 1 );

Parameters

  • $locale (string): The current locale being used for the template.

Use Case

This functionality is useful when:

  • You need to set a specific locale for certain templates (e.g., a registration template).
  • External factors, such as user input or request parameters, should influence the template’s language or localization.

Implementation Example

The following example sets a custom locale for a registration template identified by a constant:

add_filter( "wr_get_template_locale", array( $this, "set_wp_language_by_registration_email" ), 20, 1 );
 
public function set_wp_language_by_registration_email( $locale ) {  
    if ( isset( $_POST['GET']["template"] ) && (string)$_POST['GET']["template"] === Constants::TEMPLATE_REGISTRATION ) {  
    
		// Perform your custom locale logic here
        $locale = "custom_locale";
    }  
  
    return $locale;  
}