Purpose

Modify the options available in a select field programmatically. This filter allows developers to dynamically adjust the options for specific form fields based on custom logic.

Usage

add_filter( "wr_form_field_modify_select_options", array( $this, "set_system_language_options" ), 2, 10 );

Parameters

  • $options (array): The default options for the select field.
  • $field (FormFieldView|FormField): The form field object, which includes details about the field and its context.

Use Case

This functionality is useful when:

  • You need to dynamically filter or modify the selectable options in a dropdown field.
  • Specific conditions or logic dictate which options should be available for selection (e.g., restricting languages to specific ones).

Implementation Example

The following example filters the selectable options in a dropdown to include only de_DE or those containing en_GB:

add_filter( "wr_form_field_modify_select_options", array( $this, "set_system_language_options" ), 2, 10 );
 
 
public function set_system_language_options( $options, FormFieldView|FormField $field ): array {  
    
       $filtered_options = array();  
       foreach ( $this->get_all_wordpress_languages() as $lang ) {  
          if ( $lang['value'] === "de_DE" || strpos( $lang['value'], "en_GB" ) !== false ) {  
             $filtered_options[] = $lang;  
          }  
       }  
  
       return $filtered_options;  
    }  
  
    return $options;  
}