View action-filters-hooks.md

Forms and Fields

  1. Action Hook: user_meta_before_form (since 1.1.3)
    Runs when generating form. Calling just before <form> tag.
    Parameter: (string) $formName

  2. Action Hook: user_meta_after_form (since 1.1.3)
    Runs when generating form. Calling just after <form> tag.
    Parameter: (string) $formName

View generateWpmlConfig
function generateWpmlConfig() {
global $userMeta;
if ( ! $userMeta->isAdmin() ) return;
if ( ! is_writable( $userMeta->pluginPath ) ) return;
$writer = new XMLWriter();
$writer->openURI( $userMeta->pluginPath . '/wpml-config.xml');
$writer->setIndent(4);
View Add css class to fields
add_filter( 'user_meta_field_config', 'commonCssClassToAllFields', 10, 3 );
function commonCssClassToAllFields( $field, $fieldID, $formName ){
$field['field_class'] = 'my-common-class ';
return $field;
}
View Extend date range
add_filter( 'user_meta_field_config', 'user_meta_field_config_function', 10, 3 );
function user_meta_field_config_function( $field, $fieldID, $formName ){
if( $fieldID != 0 ) // Replace 0 with your filed id
return $field;
$field['field_options'] = array( "yearRange"=>"1900:c" );
return $field;
}
View Redirection after profile update
add_action( 'user_meta_after_user_update', 'user_meta_after_user_update_function' );
function user_meta_after_user_update_function( $response ){
global $userMeta;
echo $userMeta->jsRedirect( 'http://example.com' );
}
View Customize label for login form
add_filter( 'user_meta_default_login_form', 'user_meta_default_login_form_function' );
function user_meta_default_login_form_function( $config ){
$config['login_label'] = "Your desire text for login input";
$config['pass_label'] = "Your desire text for password input";
$config['remember_label'] = "Your desire text for rember me checkbox";
$config['button_value'] = "Your desire text for login button";
return $config;
}
View Use field title as placeholder
add_filter( 'user_meta_field_config', 'titleAsPlaceholder', 10, 3 );
function titleAsPlaceholder( $field, $fieldID, $formName ) {
if ( !empty( $field['field_title'] ) )
$field['placeholder'] = $field['field_title'];
return $field;
}
View add asterisk to all required fields
add_filter( 'user_meta_field_config', 'user_meta_field_config_add_asterisk', 10, 3 );
function user_meta_field_config_add_asterisk( $field, $fieldID, $formName ){
if( !empty($field['required']) || in_array($field['field_type'], array('user_login', 'user_email')) ){
if( !empty( $field['field_title'] ) )
$field['field_title'] .= '<span class="um_required">*</span>';
}
return $field;
}
View add required class to all required fields
add_filter( 'user_meta_field_config', 'user_meta_field_config_add_asterisk', 10, 3 );
function user_meta_field_config_add_asterisk( $field, $fieldID, $formName ){
if( !empty($field['required']) || in_array($field['field_type'], array('user_login', 'user_email')) ){
if( !empty( $field['field_title'] ) )
$field['field_title'] .= '<span class="um_required">*</span>';
}
return $field;
}
View Category as options
add_filter( 'user_meta_field_config', 'user_meta_field_config_populate_categories', 10, 3 );
function user_meta_field_config_populate_categories( $field, $fieldID, $formName ){
if( $fieldID != 'Your_Field_ID' ) // Put your desired field id here
return $field;
$output = null;
$cats = get_categories();
foreach( $cats as $cat ):
$output .= $cat->term_id.'='.$cat->name.',';