user_contactmethodsfilter-hookWP 2.9.0

Allows you to change a user's additional contact information.

The email and website fields are not passed through this filter.

Before version 3.6, this filter could remove or change the default contact methods (AIM, Yahoo IM, Jabber / Google Talk). These contact methods have been disabled since version 3.6.

Usage

add_filter( 'user_contactmethods', 'wp_kama_user_contactmethods_filter', 10, 2 );

/**
 * Function for `user_contactmethods` filter-hook.
 * 
 * @param string[]     $methods Array of contact method labels keyed by contact method.
 * @param WP_User|null $user    WP_User object or null if none was provided.
 *
 * @return string[]
 */
function wp_kama_user_contactmethods_filter( $methods, $user ){

	// filter...
	return $methods;
}
$methods(array)
An array of contact methods and their names.
$user(WP_User)
The user object being edited.

Examples

#1 Add additional contact information for all users

add_filter( 'user_contactmethods', 'add_user_contact_method' );

function add_user_contact_method( $method ) {

	$custom_contact = [
		'facebook' => __( 'Facebook' ),
		'twitter'  => __( 'Twitter' ),
		'whatsapp' => __( 'WhatsApp' ),
	];

	$method = array_merge( $method, $custom_contact );

	return $method;

}

Changelog

Since 2.9.0 Introduced.

Where the hook is called

wp_get_user_contact_methods()
user_contactmethods
wp-includes/user.php 3054
return apply_filters( 'user_contactmethods', $methods, $user );

Where the hook is used in WordPress

Usage not found.