Examples of action or filter hooks
user_meta_field_config (filter)
This filter hook can be use to modify fields data.
Since: 1.1.3
Parameter: (array) $formData, (int) $fieldID, (string) $formName
Supported array key for $formData:
field_title – Field Title.
field_type – Type of html input (e.g. checkbox, text, hidden, select).
field_name – Name of the field.
field_value – Retrieved value of the field.
default_value – Assign a default value when field_value is empty.
title_position – Supported value: top, left, right, inline, hidden (default: top).
description – Description of the field.
meta_key – Should use only for extra fields.
options – (string | array) Populate options for dropdown, checkbox and radio field.
max_char – Allowed maximim character.
field_size – Field size in pixel (e.g. 200px).
before – Content before field.
after – Content after field.
required – Indicate field as required.
unique – Indicate field as unique.
admin_only – If set, the field is accessible only for admin.
non_admin_only – Only viewable for non-admin
read_only – If set, read only for all user.
read_only_non_admin – If set, the field will be read only for non-admin user.
css_class – Css class for field container.
css_style – Inline css style for field container.
input_id – Input id for field itself.
field_class – Assign class to field itself.
field_style – Assign inline css stye for field itself.
label_id – Label ID.
label_class – Assign class to field label.
description_id – ID attribute for description paragraph.
description_class – Assign class to field description.
description_style – Assign inline css style for field description.
Examples:
Assign css class to field:
add_filter( 'user_meta_field_config', 'user_meta_field_config_function', 10, 3 );
function user_meta_field_config_function( $field, $fieldID, $formName ){
if( $fieldID != 'Enter field id that you need to control' )
return $field;
$field['field_class'] = 'class1 class2';
return $field;
}
Use comma in option:
add_filter( 'user_meta_field_config', 'user_meta_field_config_function', 10, 3 );
function user_meta_field_config_function( $field, $fieldID, $formName ){
if( $fieldID != 'Your field id here' )
return $field;
$field['options'] = "yes=Yes, Agree, no=No, Disagree";
return $field;
}
Note: Use ascii code of comma where you want to appear it. asciitable
User Registration
user_meta_pre_user_register (filter)
Since: 1.1.2
More validation before user registration:
add_filter( 'user_meta_pre_user_register', 'user_meta_pre_user_register_function' );
function user_meta_pre_user_register_function( $userData ){
// Write your code for more validation before user register.
// return WP_Error object if there are any error or validation failed.
return $userData;
}
Add more extra data to usermeta table:
add_filter( 'user_meta_pre_user_register', 'user_meta_pre_user_register_function' );
function user_meta_pre_user_register_function( $userData ){
// You can add some conditionl metadata
$userData[ 'new_meta_key' ] = 'New Meta Value';
return $userData;
}
user_meta_after_user_register (action)
Since: 1.1.2
Example:
add_action( 'user_meta_after_user_register', 'user_meta_after_user_register_function' );
function user_meta_after_user_register_function( $response ){
$userID = $response->ID;
// Your code goes here
}
User Export
user_meta_user_export_filename (filter)
Since: 1.2
Changing file name:
add_filter( 'user_meta_user_export_filename', function( $fileName ) {
return 'test.csv';
});
user_meta_user_export_csv_delimiter (filter)
Since: 1.2
Changing csv delimiter to |
:
add_filter( 'user_meta_user_export_csv_delimiter', function() {
return '|';
});
user_meta_user_export_csv_enclosure (filter)
Since: 1.2
Changing csv delimiter to !
:
add_filter( 'user_meta_user_export_csv_enclosure', function() {
return '!';
});
user_meta_user_export_label (filter)
Since: 1.2
Changing label of field name:
add_filter( 'user_meta_user_export_label', function ($fields) {
$fields['user_login'] = 'Renamed Username';
return $fields;
});
user_meta_user_export_fields (filter)
Since: 1.2
Changing field value:
add_filter( 'user_meta_user_export_fields', function ( $userData, $user ) {
$userData['user_login'] = 'Renamed' . $user->ID;
return $userData;
}, 10, 2);