Filter
uncanny-automator-pro
uap_option_wp_user_profile_fields
Filters user profile fields displayed on the WordPress profile page, allowing modification of available options.
add_filter( 'uap_option_wp_user_profile_fields', $callback, 10, 1 );
Description
Fires when Uncanny Automator Pro is preparing to display WordPress user profile fields. Developers can use this filter to modify, add, or remove fields shown on the user profile edit screen, allowing for dynamic customization of user data presentation within the plugin.
Usage
add_filter( 'uap_option_wp_user_profile_fields', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter `$option` is a mixed type that is passed to the `uap_option_wp_user_profile_fields` filter hook, likely representing an option related to WordPress user profile fields within the Uncanny Automator Pro plugin.
Return Value
The filtered value.
Examples
/**
* Modify Uncanny Automator Pro's user profile fields to add or alter fields for specific integrations.
*
* For example, let's say we have a custom integration with a plugin that adds a
* 'department' field to user profiles. We can use this filter to ensure that
* field is available for Uncanny Automator to use in its triggers and actions.
*
* @param array $option The current user profile field configuration.
* @return array The modified user profile field configuration.
*/
add_filter( 'uap_option_wp_user_profile_fields', function( $option ) {
// Check if we are dealing with a specific field we want to modify or add.
// In this example, we'll assume we want to add a 'user_role_level' field.
if ( ! isset( $option['user_role_level'] ) ) {
$option['user_role_level'] = array(
'label' => __( 'User Role Level', 'your-text-domain' ),
'input_type' => 'select',
'required' => false,
'options' => array(
'1' => __( 'Level 1', 'your-text-domain' ),
'2' => __( 'Level 2', 'your-text-domain' ),
'3' => __( 'Level 3', 'your-text-domain' ),
),
'relevant_tokens' => array( 'user_role_level' ), // Tokens for Automator
);
}
// Alternatively, we could modify an existing field.
// For instance, if we wanted to make the 'display_name' field required and add more options:
// if ( isset( $option['display_name'] ) ) {
// $option['display_name']['required'] = true;
// $option['display_name']['options'] = array_merge( $option['display_name']['options'], array( 'admin' => 'Admin Display Name' ) );
// }
return $option;
}, 10, 1 ); // 10 is the priority, 1 is the number of arguments accepted by the callback.
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
uncanny-automator-pro/src/integrations/wp/helpers/wp-pro-helpers.php:643
public function wp_user_profile_fields( $label = null, $option_code = 'WPUSERFIELDS', $args = array() ) {
if ( ! $label ) {
$label = __( 'Profile field', 'uncanny-automator-pro' );
}
$is_any = key_exists( 'is_any', $args ) ? $args['is_any'] : false;
$relevant_tokens = key_exists( 'relevant_tokens', $args ) ? $args['relevant_tokens'] : '';
$options = array();
if ( $is_any ) {
$options['-1'] = __( 'Any profile field', 'uncanny-automator-pro' );
}
$options['display_name'] = __( 'Display name', 'uncanny-automator-pro' );
$options['user_email'] = __( 'Email', 'uncanny-automator-pro' );
$options['user_login'] = __( 'Login', 'uncanny-automator-pro' );
$options['user_pass'] = __( 'Password', 'uncanny-automator-pro' );
$options['user_url'] = __( 'Website', 'uncanny-automator-pro' );
//$options['description'] = __( 'Biographical Info', 'uncanny-automator-pro' );
//$options['first_name'] = __( 'First name', 'uncanny-automator-pro' );
//$options['last_name'] = __( 'Last name', 'uncanny-automator-pro' );
//$options['nickname'] = __( 'Nickname', 'uncanny-automator-pro' );
$type = 'select';
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => $type,
'required' => true,
'options' => $options,
'relevant_tokens' => $relevant_tokens,
);
return apply_filters( 'uap_option_wp_user_profile_fields', $option );
}